def test_run_traffic(self, session, context): self._load_config(session, context, ALIAS, 'test_config') session.ExecuteCommand(get_reservation_id(context), ALIAS, 'Service', 'start_traffic', [InputNameValue('blocking', 'True')]) stats = session.ExecuteCommand( get_reservation_id(context), ALIAS, 'Service', 'get_statistics', [ InputNameValue('view_name', 'Test_Client'), InputNameValue('output_type', 'JSON') ]) print(json.loads(stats.Output))
def test_log_to_reservation_output(sandbox: Sandbox, rest_api: SandboxRestApiSession) -> None: """Test log to output. :todo: Assert on sandbox reservation. """ logger.addHandler(ReservationOutputHandler(sandbox)) logger.info("Hello World") output = rest_api.get_sandbox_output(get_reservation_id(sandbox)) assert output["entries"][0]["text"] == "Hello World"
def test_run_sequencer(self, session: CloudShellAPISession, context: ResourceCommandContext) -> None: self._load_config(session, context, Path(__file__).parent.joinpath("test_sequencer.tcc")) cmd_inputs = [InputNameValue("command", "Start")] session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "run_quick_test", cmd_inputs) cmd_inputs = [InputNameValue("command", "Wait")] session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "run_quick_test", cmd_inputs) time.sleep(2) cmd_inputs = [ InputNameValue("view_name", "generatorportresults"), InputNameValue("output_type", "JSON"), ] stats = session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "get_statistics", cmd_inputs) assert int( json.loads( stats.Output)["Port 1"]["GeneratorIpv4FrameCount"]) == 8000
def test_run_traffic(self, session: CloudShellAPISession, context: ResourceCommandContext) -> None: self._load_config(session, context, Path(__file__).parent.joinpath("test_config.tcc")) session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "send_arp") session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "start_protocols") cmd_inputs = [InputNameValue("blocking", "True")] session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "start_traffic", cmd_inputs) time.sleep(2) cmd_inputs = [ InputNameValue("view_name", "generatorportresults"), InputNameValue("output_type", "JSON"), ] stats = session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "get_statistics", cmd_inputs) assert int(json.loads( stats.Output)["Port 1"]["TotalFrameCount"]) >= 4000
def _load_config( self, session: CloudShellAPISession, context: ResourceCommandContext, config: Path, ) -> None: reservation_ports = get_resources_from_reservation( context, "STC Chassis Shell 2G.GenericTrafficGeneratorPort") set_family_attribute(context, reservation_ports[0].Name, "Logical Name", "Port 1") set_family_attribute(context, reservation_ports[1].Name, "Logical Name", "Port 2") cmd_inputs = [ InputNameValue("config_file_location", config.as_posix()) ] session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "load_config", cmd_inputs)
def test_sandbox_attachments(test_helpers: TestHelpers) -> None: """Test sandbox_attachments.""" test_helpers.create_reservation(RESERVATION_NAME) quali_api = SandboxAttachments(test_helpers.session.host, test_helpers.session.token_id, logging.getLogger()) quali_api.login() reservation_id = get_reservation_id(test_helpers.reservation) quali_api.attach_new_file(reservation_id, "Hello World 1", "test1.txt") quali_api.attach_new_file(reservation_id, "Hello World 2", "test2.txt") attached_files = quali_api.get_attached_files(reservation_id) assert "test1.txt" in attached_files assert "test2.txt" in attached_files test1_content = quali_api.get_attached_file(reservation_id, "test1.txt") assert test1_content.decode() == "Hello World 1" test2_content = quali_api.get_attached_file(reservation_id, "test2.txt") assert test2_content.decode() == "Hello World 2" quali_api.remove_attached_files(reservation_id) assert not quali_api.get_attached_files(reservation_id)
def test_session_id(self, session: CloudShellAPISession, context: ResourceCommandContext) -> None: session_id = session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "get_session_id") assert os.environ["COMPUTERNAME"].replace("-", "_") in session_id.Output cmd_inputs = [ InputNameValue("obj_ref", "system1"), InputNameValue("child_type", "project"), ] project = session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "get_children", cmd_inputs) assert len(json.loads(project.Output)) == 1 assert json.loads(project.Output)[0] == "project1" project_obj = json.loads(project.Output)[0] cmd_inputs = [InputNameValue("obj_ref", project_obj)] project_children = session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "get_children", cmd_inputs) assert len(json.loads(project_children.Output)) > 1 cmd_inputs = [ InputNameValue("obj_ref", "system1"), InputNameValue("child_type", "AutomationOptions"), ] options = session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "get_children", cmd_inputs) options_ref = json.loads(options.Output)[0] cmd_inputs = [InputNameValue("obj_ref", options_ref)] old_options_attrs = session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "get_attributes", cmd_inputs) cmd_inputs = [ InputNameValue("obj_ref", options_ref), InputNameValue("attr_name", "LogLevel"), InputNameValue("attr_value", "INFO"), ] session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "set_attribute", cmd_inputs) cmd_inputs = [InputNameValue("obj_ref", options_ref)] new_options_attrs = session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "get_attributes", cmd_inputs) assert json.loads(old_options_attrs.Output)["LogLevel"] != json.loads( new_options_attrs.Output)["LogLevel"] assert json.loads(new_options_attrs.Output)["LogLevel"] == "INFO" parameters = { "Parent": project_obj, "ResultParent": project_obj, "ConfigType": "Generator", "ResultType": "GeneratorPortResults", } cmd_inputs = [ InputNameValue("command", "ResultsSubscribe"), InputNameValue("parameters_json", json.dumps(parameters)), ] output = session.ExecuteCommand(get_reservation_id(context), ALIAS, "Service", "perform_command", cmd_inputs) assert json.loads(output.Output)["State"] == "COMPLETED"
def _load_config(self, session, context, alias, config_name): config_file = Path(__file__).parent.joinpath(f'{config_name}.rxf') session.ExecuteCommand( get_reservation_id(context), alias, 'Service', 'load_config', [InputNameValue('config_file_location', config_file.as_posix())])