def test_network_ls_json(tmp_file, capture_stdout): """ List node networks (json format) """ nodemgr.main( argv=["network", "ls", "--format", "json", "--color", "no"]) with capture_stdout(tmp_file): ret = nodemgr.main( argv=["network", "ls", "--format", "json", "--color", "no"]) assert ret == 0 with open(tmp_file) as std_out: assert isinstance(json.load(std_out), dict)
def test_set_env_comment(): """ Set node env.comment to a unicode string """ ret = nodemgr.main( argv=["set", "--param", "env.comment", "--value", UNICODE_STRING]) assert ret == 0
def test_node_has_a_pool(tmp_file, capture_stdout): with capture_stdout(tmp_file): assert nodemgr.main( argv=['pool', 'status', '--format', 'json']) == 0 with open(tmp_file) as json_file: pools = json.load(json_file).values() assert len([pool for pool in pools if pool['type'] != 'unknown']) > 0
def test_it_call_once_node_action_and_returns_node_action_return_value( node, parse_args, action_return_value): node.action.return_value = action_return_value ret = nodemgr.main(argv=["my_action", "--format", "json"]) assert ret == action_return_value node.action.assert_called_once_with('my_action')
def test_0259_compliance(): """ Node compliance detach """ ret = nodemgr.main(argv=[ "compliance", "detach", "--ruleset", "abcdef", "--moduleset", "abcdef" ]) assert ret == 0
def test_001(self): """ cli ls """ ret = nodemgr.main(argv=[ CONFIG, "collector", "cli", "ls", ]) assert ret == 0
def test_000(self): """ cli get /users/self """ ret = nodemgr.main(argv=[ CONFIG, "collector", "cli", "get", "/users/self", ]) assert ret == 0
def test_get_env_comment(tmp_file, capture_stdout): """ Get node env.comment """ with capture_stdout(tmp_file): ret = nodemgr.main(argv=["get", "--param", "env.comment"]) assert ret == 0 from rcUtilities import try_decode with open(tmp_file) as output_file: assert try_decode(output_file.read()) == UNICODE_STRING
def test_011(self): """ cli POST /groups """ ret = nodemgr.main(argv=[ CONFIG, "collector", "cli", "post", "/groups", "--data", "role=unittest", ])
def test_print_config_json(tmp_file, capture_stdout): """ Print node config (json format) """ with capture_stdout(tmp_file): ret = nodemgr.main( argv=["print", "config", "--format", "json", "--color", "no"]) with open(tmp_file) as json_file: config = json.load(json_file) assert ret == 0 assert isinstance(config, dict)
def test_set_get_unset_some_env_value(tmp_file, capture_stdout, get_set_arg): ret = nodemgr.main( argv=["set", "--param", "env.this_is_test", "--value", "true"]) assert ret == 0 with capture_stdout(tmp_file): ret = nodemgr.main(argv=["get", get_set_arg, "env.this_is_test"]) assert ret == 0 from rcUtilities import try_decode with open(tmp_file) as output_file: assert try_decode(output_file.read()).strip() == "true" ret = nodemgr.main(argv=["unset", get_set_arg, "env.this_is_test"]) assert ret == 0 tmp_file_1 = tmp_file + '-1' with capture_stdout(tmp_file_1): ret = nodemgr.main(argv=["get", get_set_arg, "env.this_is_test"]) assert ret == 0 with open(tmp_file_1) as output_file: assert output_file.read().strip() == "None"
def test_print_schedule_json(tmp_file, capture_stdout): """ Print node schedules (json format) """ with capture_stdout(tmp_file): ret = nodemgr.main(argv=[ "print", "schedule", "--format", "json", "--color", "no" ]) assert ret == 0 with open(tmp_file) as json_file: schedules = json.load(json_file) assert isinstance(schedules, list) assert len(schedules) > 0
def test_103(self): """ cli moduleset recreate 1 """ ret = nodemgr.main(argv=[ CONFIG, "collector", "cli", "moduleset", "--create", "--moduleset", "unittest1", ]) assert ret == 0
def test_104(self): """ cli moduleset add responsible """ ret = nodemgr.main(argv=[ CONFIG, "collector", "cli", "moduleset", "--attach", "--moduleset", "unittest1", "--responsible-group", "unittest", "--publication-group", "unittest", ]) assert ret == 0
def test_161_nodemgr_print_devs(): """ Print node device tree """ ret = nodemgr.main(argv=["print", "devs"]) assert ret == 0
def test_prkey_create_initial_value_when_absent(tmp_file, capture_stdout): with capture_stdout(tmp_file): ret = nodemgr.main(argv=["prkey"]) assert ret == 0 with open(tmp_file) as std_out: assert std_out.read().startswith('0x')
def test_pool_action(argv): assert nodemgr.main(argv=argv) == 0
def test_print_schedule(): """ Print node schedules """ ret = nodemgr.main(argv=["print", "schedule"]) assert ret == 0
def test_164_nodemgr_collector_networks(): """ Collector networks """ ret = nodemgr.main(argv=["collector", "networks"]) assert ret == 0
def test_0257_compliance(): """ Node compliance list ruleset """ ret = nodemgr.main(argv=["compliance", "list", "ruleset"]) assert ret == 0
def test_0256_compliance(): """ Node compliance show ruleset """ ret = nodemgr.main(argv=["compliance", "show", "ruleset"]) assert ret == 0
def test_163_nodemgr_dequeue_actions(): """ Dequeue actions """ ret = nodemgr.main(argv=["dequeue", "actions"]) assert ret == 0
def test_0251_compliance(): """ Node compliance auto """ ret = nodemgr.main(argv=["compliance", "auto"]) assert ret == 0
def test_164_nodemgr_collector_search(): """ Collector search """ ret = nodemgr.main(argv=["collector", "search", "--like", "safe:%"]) assert ret == 0
def test_network_ls(): """ List node networks """ ret = nodemgr.main(argv=["network", "ls"]) assert ret == 0
def test_prkey_show_existing_prkey(tmp_file, capture_stdout): nodemgr.main(argv=['set', '--kw', 'node.prkey=0x8796759710111']) with capture_stdout(tmp_file): assert nodemgr.main(argv=["prkey"]) == 0 with open(tmp_file) as output_file: assert output_file.read().strip() == '0x8796759710111'
def test_0252_compliance(): """ Node compliance check """ ret = nodemgr.main(argv=["compliance", "check"]) assert ret == 0
def test_164_nodemgr_scan_scsi(): """ Scan scsi buses """ ret = nodemgr.main(argv=["scanscsi"]) assert ret == 0
def test_start_status_restart_stop_with_running_check( mock_argv, mocker, capture_stdout, tmp_file): wait_time_for_osvcd_ready = 8 if 'OPENSVC_CI_EXTRA_TIME_OSVCD_STARTUP' in os.environ: # give extra time when slow ci extra_wait_time = int( os.environ['OPENSVC_CI_EXTRA_TIME_OSVCD_STARTUP']) print('wait extra time: OPENSVC_CI_EXTRA_TIME_OSVCD_STARTUP=%s' % extra_wait_time) wait_time_for_osvcd_ready += extra_wait_time def osvcd_main_start(): mock_argv([]) main() def daemon_start_native(_): from multiprocessing import Process proc = Process(target=osvcd_main_start) proc.start() proc.join() return 0 mocker.patch.object(Node, 'daemon_start_native', daemon_start_native) mocker.patch.object(Node, 'daemon_handled_by_systemd', return_value=False) mocker.patch('rcAsset.Asset.get_boot_id', side_effect='fake_boot_id') print('daemon is not running') assert nodemgr.main(argv=["daemon", "running", "--debug"]) > 0 print('daemon start...') assert nodemgr.main(argv=["daemon", "start", "--debug"]) == 0 print('daemon is running...') assert nodemgr.main(argv=["daemon", "running", "--debug"]) == 0 print('sleep %ss for osvcd ready' % wait_time_for_osvcd_ready) time.sleep(wait_time_for_osvcd_ready) print('daemon status json...') with capture_stdout(tmp_file): assert nodemgr.main( argv=["daemon", "status", "--format", "json"]) == 0 with open(tmp_file, 'r') as status_file: status = json.load(status_file) print(status) assert status['listener']['state'] == 'running' assert status['scheduler']['state'] == 'running' print('daemon status...') assert nodemgr.main(argv=["daemon", "status", "--debug"]) == 0 print('daemon restart...') assert nodemgr.main(argv=["daemon", "restart", "--debug"]) == 0 print('daemon is running...') assert nodemgr.main(argv=["daemon", "running", "--debug"]) == 0 print('sleep %ss for osvcd ready' % wait_time_for_osvcd_ready) time.sleep(wait_time_for_osvcd_ready) print('daemon stop...') assert nodemgr.main(argv=["daemon", "stop", "--debug"]) == 0 print('daemon is not running...') assert nodemgr.main(argv=["daemon", "running", "--debug"]) > 0
def test_0253_compliance(): """ Node compliance fix """ ret = nodemgr.main(argv=["compliance", "fix"]) assert ret == 0