Package: cognicept-shell
COGNICEPT SHELLThis is a shell utility to manage Cognicept tools.InstallationDependenciesPackage installationUsageCommandsBuildingTestsBuildUploadContributionVersion historyInstallationDependenciesYou need:Python 3Python 3 PIPopenssh-server: (Optional) in order to enable terminal function for KriyaInstall:sudo apt-get install python3 python3-pipPackage installationTo install the package locally, run:pip3 install -e <path-to-the-repo>To install from Python Package Index (PyPI), run:pip3 install cognicept-shellTo verify installation, try to runcognicept -hIf you getcognicept: command not founderror, make sure that~/.local/bin/is in your$PATH. You could run this:export PATH=$PATH:/home/$USER/.local/bin/and add it to your.bashrcfile.AutocompleteTo set-up autcomplete when using the cognicept shell, run:cognicept config --autocompleteRestart the terminal and autocomplete should be functioningThis will setup python argcomplete globally and may affect other packages. If argcomplete has been setup globally for other project, this setup is not required.This command essentially calls the functionactivate-global-python-argcompleteMore information about this can be found inhttps://pypi.org/project/argcomplete/#activating-global-completionUsageFor details on usage, usecognicept -hCommandsconfig: Configure Cognicept toolscognicept-shelland Cognicept agents are configured inruntime.envfile typically placed in~/.cognicept/runtime.env. The file defines the docker environment used by the Cognicept agents.This command allows to inspect and modify the configuration file. You can use parameter--pathto modify the path to the Cognicept config directory.To print full configuration, run:cognicept config --readTo add new configuration parameter (or modify single value), run:cognicept config --addVariables used bycognicept-shell:COGNICEPT_ACCESS_KEYCOGNICEPT_API_URICOGNICEPT_USER_API_URICOG_AGENT_CONTAINERSCOG_AGENT_IMAGESCOG_EXTRA_IMAGES: images to pull from Cognicept and general docker image repositoriesCOG_ORBITTY_ENABLEDCOG_ORBITTY_IMAGEAWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_SESSION_TOKEN: temporary AWS credentials modified bykeyrotateand needed forupdateCOG_ENABLE_SSHCOG_ENABLE_SSH_KEY_AUTHCOG_ENABLE_AUTOMATIC_SSHCOG_SSH_DEFAULT_USERTo setupsshaccess fromremote_intervention_agentto the host machine, run:cognicept config --sshTo setup autocomplete from cognicept shell, run:cognicept config --autoIt will generate ssh keys in~/.cognicept/ssh/and configuresCOG_ENABLE_SSH,COG_ENABLE_SSH_KEY_AUTH,COG_ENABLE_AUTOMATIC_SSH,COG_SSH_DEFAULT_USERaccording to the user preferences. IfCOG_ENABLE_AUTOMATIC_SSHis enabled, public key is copied into~/.ssh/authorized_hosts;sudoaccess is requested to perform this action.status: Get status of Cognicept agentscognicept statusPrints status of agents and other containers managed bycognicept-shell. Possible values:"ONLINE": Everything fine"CONTAINER NOT FOUND": Agent/container is not initiated"OFFLINE": Container stopped"Error": Error accessing API"ERROR": Detected error, needs inspection"NOT INITIALIZED": Agent is in init state"STALE": Agent didn't update within last minuteversion: Display Cognicept Shell and Container versioncognicept versionPrints the version of current cognicept shell and other containers versionupdate: Update Cognicept toolsUpdates images for agents and tools specified inCOG_AGENT_IMAGESandCOG_EXTRA_IMAGESconfig variables. It requires temporary credentials to be valid. If the available disk space is less than 3 GB, the update will not proceed. This check ensures that there is sufficient space for the update to run successfully. For updates to take effect, containers need to be restarted withrestartcommand.To run update in detached mode:cognicept update -dIn detached mode, printing of update statuses in muted. Update is run in a seperate process. Update will continue to run even if terminal session is closed.To update docker images in environment variableCOGNICEPT_EXTRA_IMAGEScognicept update --image <docker-images-repo>To override the disk space check before pulling images:cognicept update -sthe disk space check will be bypassed, and the update will proceed regardless of the available disk spacelastevent: Display last event log reported by Cognicept agentDisplays last event saved bycgs_diagnostics_agentfrom~/.cognicept/logs.start/stop/restart: start/stop/restart cognicept agentsThese commands are used to start/stop/restart containers specified inCOG_AGENT_CONTAINERS/COG_AGENT_IMAGES. Certain container names are reserved for Cognicept agents and are preconfigured:cgs_diagnostics_agentremote_intervention_agentkriya_watchdogcgs_diagnostics_ecs_apicgs_diagnostics_streamer_apicgs_bagger_serverhealth_aggregatordiagnostics_aggregatorkopilotsmartplus_soundmap_managercomputer_health_metricsslamtec_adaptercam_captureAny agent name or image type can be put in the list as long as default command for the image is specified. All containers are started inhostnetwork mode.Following are examples for usingstart.stopfollows same API asstart.restartfirst callsstopand thenstop.To start all listed agentsCOG_AGENT_CONTAINERSdon't specify any argument:cognicept startTo start all agents:cognicept start --agentsTo start specific agents:cognicept start remote_intervention_agent cgs_diagnostics_agentTo run restart in detached mode:cognicept restart -dDetached mode is particularly useful for restarting a cognicept agent remotely.
In detached mode, progress of restart will not printed.To restart and clearing logscognicept restart --prunekeyrotate: Rotate Cognicept cloud keysUpdates temporary AWS credentials (AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_SESSION_TOKEN) usingCOGNICEPT_ACCESS_KEYfromCOGNICEPT_API_URI. The validity of the credentials is 12 hours. Internet access with HTTPS allowed is needed.orbitty: Run OrbittyTODOrecord: Manage rosbag recording session to start/stop/pause/resume/get status/record all topicsThese commands are used to start/stop/pause/resume/get status/record all topics in a rosbag. All the operations are done by running anexeccommand inside thecgs_bagger_servercontainer. All bags are typically placed in thebagsfolder of the Cognicept configuration directory:~/.cognicept/bags/To start start a recording session list all topics to be recorded separated by a space and with their/prefix:cognicept record --start /odom /cmd_vel /rosout_agg /tf /tf_staticTo record ALL topics use--all:NOTE:rosbags tend to become quite big quite fast especially if there are camera topics. If there is less than 1 GB disk space, the recording self terminates.cognicept record --allTo stop a recording session:cognicept record --stopAlternatively, the latest bag recording can be stopped and automatically pushed to the Cognicept cloud with a single command by providingautopushvalue:cognicept record --stop autopushTo pause a recording session:cognicept record --pauseTo resume a recording session:cognicept record --resumeTo get the status of the current recording:cognicept record --statusStatus can beReady,Started,Stopped,PausedandResumed.NOTE:A note on the retry mechanisms built in to improve reliability. If the retry mechanism fails, bothcognicept record --startandcognicept record --allwill automatically restart thecgs_bagger_server. A new recording session needs to be started if this happens. All other commands will just inform that the retry has failed since these are not essential operations for bag recording.push: Push data to Cognicept cloudThese commands are used to push data on to the Cognicept cloud.To push a bag file, specify the name of the bag file:cognicept push --bag sample_recording.bagNOTE:Only bags in the dedicated Cognicept configurationbagsdirectory, usually~/.cognicept/bags, will be detected and uploaded. Bag files in any other location need to be moved to this directory before upload. Bag files generated using thecognicept recordfeature will be automatically placed in the Cognicept configurationbagsdirectory.As a shorthand, you can push the latest bag file recording by not specifying any argument. This will automatically look for the latest bag file by create time and upload it:cognicept push --baginit: Initiates the runtime.env file with values from the COGNICEPT_USER_API_URITo initiate a runtime.env file, specify the robot id and organisation id and then provide credentials when promptedcognicept init --robot_id sample_robot --org_id sample_org
Username: sample_username
Password: sample_password (masked)Docker-Composeis supported in version1.6for cognicept-shell command below:cognicept update/version/start/stop/restartTo make it work, you should added an enviroment variableCOG_COMPOSE_FILEin~/.cognicept/runtime.envand specific the file directory of the docker-compose.yaml file, egCOG_COMPOSE_FILE=~/.cognicept/docker-compose.yamlSample of docker-compose file:version:"3.9"services:service_name:container_name:service_namenetwork_mode:"host"restart:unless-stoppedenv_file:-${HOME}/.cognicept/runtime.envimage:image_repocommand:python3 example.pySample response after runningcognicept versionCogniceptShellVersion1.6.0
+------------------------------+-----------+----------------+|ContainerName|Version|VersionTags||------------------------------+-----------+----------------||remote_intervention_agent|latest|latest||kriya_watchdog|latest|latest||cgs_diagnostics_ecs_api|dev|latest||cgs_diagnostics_streamer_api|dev|latest||cgs_diagnostics_agent|dev|latest||service_name|||+------------------------------+-----------+----------------+
Runtimeenviromentfiledirectory:~/.cognicept/move: to move a robot from one organisation to anotherThe `cognicept move`` command allows you to move a robot to a different organization with the following flags:--robot_id: Specify the desired robot_id.--old_org_id: Provide the organization id where the robot is currently residing.--new_org_id: Indicate the target organization id to which you want to move the robot.--skip: You can use this flag to specify if you want to skip the moving of any of the following robot data:map: Skip moving the map data.schedule: Skip moving the schedule data.waypoint: Skip moving the waypoint data.Example (without skip):cognicept move --robot_id=<robot_id> --old_org_id=<old_org_id> --new_org_id=<new_org_id>This command will move the specified robot to the new organization without skipping any data.Example (with skip):cognicept move --robot_id=<robot_id> --old_org_id=<old_org_id> --new_org_id=<new_org_id> --skip waypoint mapThis command will move the robot while skipping the move map and waypointGetting Robot OnlineAfter moving the robot to the new organization, there are additional steps required to get the robot online. Follow these steps:Navigate to the terminal connected to the robot.Run the following command, replacing<new org id>and<new robot id>with the actual values displayed after runningcognicept move:cognicept init --org_id <new org id> --robot_id <new robot id>This command updates theruntime.envconfiguration file inside the robot with its new robot_code, site_code, agent_id, cognicept_access_key, and aws_webrtc_channel_arn.Run thecognicept keyrotatecommand.Run thecognicept restartcommand. Note: by default it is restart in detach mode.After completing these steps, wait for a few minutes, and the robot should be online in the new organization.BuildingTestscognicept-shellis usingpytestas the test framework. Make sure you install manually:pip3 install pytest pytest-cov cli_test_helpers mockTo run tests, execute:pytest --cov=cogniceptshell testsOutput will look like this:user@computer:~/cognicept-shell$ pytest --cov=cogniceptshell tests
============================= test session starts ==============================
platform linux -- Python 3.8.5, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: /home/jakub/code/cognicept-shell
plugins: cov-2.10.0
collected 50 items                                                             

tests/functional/test_config.py ........s                                [ 18%]
tests/functional/test_push.py ..........                                 [ 38%]
tests/functional/test_record.py ..........                               [ 58%]
tests/unit/test_config.py ....                                           [ 66%]
tests/unit/test_keyrotate.py ...                                         [ 72%]
tests/unit/test_lifecycle.py ..............                              [100%]

----------- coverage: platform linux, python 3.8.5-final-0 -----------
Name                                 Stmts   Miss  Cover
--------------------------------------------------------
cogniceptshell/__init__.py               2      0   100%
cogniceptshell/agent_life_cycle.py     319    117    63%
cogniceptshell/common.py                15      5    67%
cogniceptshell/configuration.py        189     53    72%
cogniceptshell/interface.py             79      2    97%
cogniceptshell/pusher.py               104     11    89%
cogniceptshell/rosbag_record.py         90     13    86%
--------------------------------------------------------
TOTAL                                  798    201    75%


======================== 49 passed, 1 skipped in 28.59s ========================BuildTo build the PyPI package, run:python3 setup.py sdist bdist_wheelThis will generate the build files.UploadTo upload the dev package, run:python3 -m twine upload --repository testpypi dist/* --verboseTo upload the prod package, run:python3 -m twine upload dist/* --verboseContributionPlease followthe successful branching model. The naming of branches follows:Feature branch: /feature/name-of-the-featureBug fix branch: /fix/name-of-the-bugRelease branch: /release/name-of-the-releaseVersion history1.7.1[24/11/2023]Bug Fixed - templates directory blocking cognicept restartcognicept prune to support only in attached mode1.7.0[25/10/2023]cognicept updatecheck for remaining disk space (in root directory) before pulling each imagecognicept update -soverrides check for disk space before pulling imagescognicept updatewill update the success or failure to S+ event logscognicept versionwill display the latest version of the docker imagescognicept restartby default is restarting in detached modecognicept restart-a to restart in attached modecognicept initsupport --robot_code and --org_codenewcognicept movefeature1.6.1[22/5/2023]cognicept updateprompts the user before upgrading the cognicept-shell versioncognicept update -ywill upgrade cognicept-shell directlyFixedcognicept initbug for non-existing robot_id and org_idAdded exception handling to capture HTTP status codes in shellChanged cognicept version update message to reflect the latest versionAdded install_requires forwebsocket-client,paramikodependenciesAdded docker-compose error handling exception1.6 [12/5/2023]cognicept update/version/start/stop/restartsupport of docker-compose with enviroment variableCOG_COMPOSE_FILEcognicept restart --prunefor clearing logscognicept update --imageto update docker images in environment variableCOGNICEPT_EXTRA_IMAGEScognicept updatewill prompts msgs for users about the specific errors faced when trying to runcognicept updateadded camera_capture1.5 [23/9/2022]Auto update shell oncognicept updateAllow container specific updatesAdd support for kopilot, smartplus_sound_server, map_manager, kriya's friendsAudio config for sound devicesBackup runtime config before updating1.4 [16/12/2021]2FA modification forinitcommandAddversioncommand to display agent versionAdd support for health_monitoring_aggregator1.3 [21/10/2021]Autocomplete for basic commands and agent names1.2 [29/6/2021]Revamp credentials for AWSAdded robot init commandRevamped CI/CDAdded detached update/restartRemoved datadog integrationAdded kriya watchdog run configurationAdded handling of the docker permission errorAdded run configuration to support bunch reporting1.1 []Limit agent logs to 5MB1.0.3 []Change for cognicept update command to fetch cloud credentials from cognicept backend1.0 [15/12/2020]AddedstartcommandStart/Stop/Restart agents separately as parameter of commandMigrated to new credential management usingCOGNICEPT_ACCESS_KEYAddedkeyrotatecommandAdded unit and functional testsAddedrecordandpushcommands for management of rosbagsAdded support for Python 3.5Addedlasteventcommand to read last eventAdded ssh configuration forremote_intervention_agent0.1 [10/6/2020]First version of the CLI utility able to configure, restart, and update agents