Exemplo n.º 1
0
 def test_resource_option_is_not_preserved_on_next_mgr_call():
     assert Mgr()(argv=["-s", "svc1", "create"]) == 0
     assert Mgr()(argv=[
         "-s", "svc1", "update", "--resource", '{"comment": "foo"}',
         "--local"
     ]) == 0
     assert Mgr()(argv=["-s", "svc2", "create"]) == 0
Exemplo n.º 2
0
 def test_delete_service():
     svcname = "a-service"
     assert Mgr()(
         argv=["-s", svcname, "create", "--kw", "env.foo=bar"]) == 0
     assert Mgr()(argv=["-s", svcname, "ls"]) == 0
     assert Mgr()(argv=["-s", svcname, "delete", "--local"]) == 0
     assert Mgr()(argv=["-s", svcname, "ls"]) == 1
Exemplo n.º 3
0
 def test_refuse_dry_run():
     svcname = "pytest"
     assert Mgr()(
         argv=["-s", svcname, "create", "--kw", "env.foo=bar"]) == 0
     assert Mgr()(
         argv=["-s", svcname, "delete", "--dry-run", "--local"]) == 1
     assert Mgr()(argv=["-s", svcname, "ls"]) == 0
Exemplo n.º 4
0
    def test_refuse_dry_run():
        svcname = "pytest"
        assert Mgr()(argv=["-s", svcname, "create"]) == 0

        assert Mgr()(argv=[
            "-s", svcname, "update", "--resource", '{"comment": "Comment"}',
            "--local", "--dry-run"
        ]) == 1
Exemplo n.º 5
0
 def test_update_config(tmp_file, capture_stdout):
     svcname = "pytest"
     assert Mgr()(
         argv=["-s", svcname, "create", "--kw", "env.foo=bar"]) == 0
     assert Mgr()(
         argv=["-s", svcname, "unset", "--kw", "env.foo", "--local"]) == 0
     with capture_stdout(tmp_file):
         assert Mgr(
         )(argv=["-s", svcname, "print", "config", "--format", "json"]) == 0
     assert "foo" not in json.load(open(tmp_file, "r"))["env"]
Exemplo n.º 6
0
 def test_remove_section(tmp_file, capture_stdout):
     svcname = "pytest"
     assert Mgr()(
         argv=["-s", svcname, "create", "--kw", "env.foo=bar"]) == 0
     assert Mgr()(
         argv=["-s", svcname, "delete", "--rid", "env", "--local"]) == 0
     with capture_stdout(tmp_file):
         assert Mgr(
         )(argv=["-s", svcname, "print", "config", "--format", "json"]) == 0
     assert "env" not in json.load(open(tmp_file, "r"))
Exemplo n.º 7
0
    def test_it_updates_config(mock_sysname, tmp_file, capture_stdout):
        svcname = "pytest"
        mock_sysname("linux")
        assert Mgr()(argv=["-s", svcname, "create"]) == 0

        assert Mgr()(argv=[
            "-s", svcname, "update", "--resource",
            '{"rid": "fs#1", "type": "flag"}', "--local"
        ]) == 0
        with capture_stdout(tmp_file):
            assert Mgr(
            )(argv=["-s", svcname, "print", "config", "--format", "json"]) == 0
        assert json.load(open(tmp_file, "r"))["fs#1"] == {"type": "flag"}
Exemplo n.º 8
0
 def test_define_correct_default_status_schedule_of_10(
         mocker, tmp_file, capture_stdout):
     svcname = "pytest"
     mocker.patch.dict(os.environ, {"OSVC_DETACHED": "1"})
     assert Mgr()(argv=["-s", svcname, "create"]) == 0
     assert Mgr()(argv=["-s", svcname, "print", "schedule"]) == 0
     with capture_stdout(tmp_file):
         assert Mgr()(
             argv=["-s", svcname, "print", "schedule", "--format", "json"
                   ]) == 0
     assert get_action(json.load(open(tmp_file, "r")), "status") == {
         "action": "status",
         "config_parameter": "DEFAULT.status_schedule",
         "last_run": "-",
         "schedule_definition": "@10"
     }
Exemplo n.º 9
0
 def test_002_set_default(self):
     """
     Set references
     """
     refs = ["--kw", "nodes=%s" % NODENAME]
     for idx, (name, val, exp_val) in enumerate(REFS):
         refs += ["--kw", "%s=%s" % (name, val)]
     ret = Mgr()(argv=["-s", SVCNAME, "set"] + refs)
     assert ret == 0
Exemplo n.º 10
0
 def assert_service_avail(value):
     cmd_args = [
         "-s", svcname, 'print', 'status', '-r', '--format', 'json'
     ]
     print('run Mgr()(argv=%s)' % cmd_args)
     with capture_stdout(tmp_file):
         assert Mgr()(argv=cmd_args) == 0
     with open(tmp_file, 'r') as status_file:
         status = json.load(status_file)
     print(json.dumps(status, indent=4))
     if value is 'down' and 'standby' in svcname:
         value = 'stdby ' + value
     print('assert service avail is ', value)
     assert status['avail'] == value
Exemplo n.º 11
0
    def __get_ref(self, idx):
        """
        Get ref
        """
        name, val, exp_val = REFS[idx]
        _stdout = sys.stdout

        try:
            out = StringIO()
            sys.stdout = out
            ret = Mgr()(argv=["-s", SVCNAME, "get", "--eval", "--kw", name])
            output = out.getvalue().strip()
        finally:
            sys.stdout = _stdout
        print(ret, output, exp_val)
        assert ret == 0
        assert try_decode(output) == exp_val
Exemplo n.º 12
0
 def test_define_correct_schedule(mocker, tmp_file, capture_stdout):
     svcname = "pytest"
     mocker.patch.dict(os.environ, {"OSVC_DETACHED": "1"})
     assert_run_cmd_success(svcname, [
         "create", "--kw", "task#1.command=/usr/bin/date", "--kw",
         "task#1.schedule=@3"
     ])
     assert_run_cmd_success(svcname, ["print", "schedule"])
     with capture_stdout(tmp_file):
         assert Mgr()(
             argv=["-s", svcname, "print", "schedule", "--format", "json"
                   ]) == 0
     schedule_run = [
         schedule for schedule in json.load(open(tmp_file, "r"))
         if schedule["action"] == "run"
     ][0]
     assert schedule_run == {
         "action": "run",
         "config_parameter": "task#1.schedule",
         "last_run": "-",
         "schedule_definition": "@3"
     }
Exemplo n.º 13
0
 def test_001_create_empty(self):
     """
     Create a trivial service
     """
     ret = Mgr()(argv=["create", "-s", SVCNAME])
     assert ret == 0
Exemplo n.º 14
0
 def test_004_delete(self):
     """
     Delete local service instance
     """
     ret = Mgr()(argv=["delete", "-s", SVCNAME, "--local"])
     assert ret == 0
Exemplo n.º 15
0
def assert_run_cmd_success(svcname, svc_cmd_args):
    cmd_args = ["-s", svcname] + svc_cmd_args
    print('--------------')
    print('run Mgr()(argv=%s)' % cmd_args)
    assert Mgr()(argv=cmd_args) == 0
Exemplo n.º 16
0
def main():
    try:
        arg1 = sys.argv[1]
    except IndexError:
        print(HELP, file=sys.stderr)
        return 1
    if arg1 == "ns":
        print("The 'om' alias must be sourced to handle ns actions",
              file=sys.stderr)
        return 1
    elif arg1 == "ctx":
        from core.contexts import main
        ret = main(sys.argv[1:])
        return ret
    elif arg1 == "svc":
        from commands.svc import Mgr
        os.environ["OSVC_KIND"] = arg1
        ret = Mgr()(argv=sys.argv[2:])
        return ret
    elif arg1 == "vol":
        from commands.vol import Mgr
        os.environ["OSVC_KIND"] = arg1
        ret = Mgr()(argv=sys.argv[2:])
        return ret
    elif arg1 == "cfg":
        from commands.cfg import Mgr
        os.environ["OSVC_KIND"] = arg1
        ret = Mgr()(argv=sys.argv[2:])
        return ret
    elif arg1 == "sec":
        from commands.sec import Mgr
        os.environ["OSVC_KIND"] = arg1
        ret = Mgr()(argv=sys.argv[2:])
        return ret
    elif arg1 == "usr":
        from commands.usr import Mgr
        os.environ["OSVC_KIND"] = arg1
        ret = Mgr()(argv=sys.argv[2:])
        return ret
    elif arg1 == "node":
        from commands.node import main
        ret = main(argv=sys.argv[2:])
        return ret
    elif arg1 == "array":
        from commands.node import main
        ret = main(argv=sys.argv[1:])
        return ret
    elif arg1 in ("net", "network"):
        from commands.network import main
        ret = main(argv=sys.argv[2:])
        return ret
    elif arg1 == "pool":
        from commands.pool import main
        ret = main(argv=sys.argv[2:])
        return ret
    elif arg1 == "daemon":
        from commands.daemon import main
        ret = main(argv=sys.argv[2:])
        return ret
    elif arg1 == "mon":
        from commands.svcmon import main
        ret = main(argv=sys.argv[1:])
        return ret
    else:
        from commands.mgr import Mgr
        ret = Mgr(selector=arg1)(argv=sys.argv[2:])
        return ret
Exemplo n.º 17
0
 def test_update_allowed_without_resource():
     svcname = "pytest"
     assert Mgr()(argv=["-s", svcname, "create"]) == 0
     assert Mgr()(argv=["-s", svcname, "update", "--local"]) == 0