示例#1
0
    def test_status_wrapper_init_local_writes_fresh_status_info(self):
        """When running in init-local mode, status_wrapper writes status.json.

        Old status and results artifacts are also removed.
        """
        tmpd = self.tmp_dir()
        data_d = self.tmp_path('data', tmpd)
        link_d = self.tmp_path('link', tmpd)
        status_link = self.tmp_path('status.json', link_d)
        # Write old artifacts which will be removed or updated.
        for _dir in data_d, link_d:
            test_helpers.populate_dir(_dir, {
                'status.json': 'old',
                'result.json': 'old'
            })

        FakeArgs = namedtuple('FakeArgs', ['action', 'local', 'mode'])

        def myaction(name, args):
            # Return an error to watch status capture them
            return 'SomeDatasource', ['an error']

        myargs = FakeArgs(('ignored_name', myaction), True, 'bogusmode')
        cli.status_wrapper('init', myargs, data_d, link_d)
        # No errors reported in status
        status_v1 = load_json(load_file(status_link))['v1']
        self.assertEqual(['an error'], status_v1['init-local']['errors'])
        self.assertEqual('SomeDatasource', status_v1['datasource'])
        self.assertFalse(os.path.exists(self.tmp_path('result.json', data_d)),
                         'unexpected result.json found')
        self.assertFalse(os.path.exists(self.tmp_path('result.json', link_d)),
                         'unexpected result.json link found')
示例#2
0
    def test_status_wrapper_init_local_writes_fresh_status_info(self, tmpdir):
        """When running in init-local mode, status_wrapper writes status.json.

        Old status and results artifacts are also removed.
        """
        data_d = tmpdir.join("data")
        link_d = tmpdir.join("link")
        status_link = link_d.join("status.json")
        # Write old artifacts which will be removed or updated.
        for _dir in data_d, link_d:
            test_helpers.populate_dir(str(_dir), {
                "status.json": "old",
                "result.json": "old"
            })

        FakeArgs = namedtuple("FakeArgs", ["action", "local", "mode"])

        def myaction(name, args):
            # Return an error to watch status capture them
            return "SomeDatasource", ["an error"]

        myargs = FakeArgs(("ignored_name", myaction), True, "bogusmode")
        cli.status_wrapper("init", myargs, data_d, link_d)
        # No errors reported in status
        status_v1 = load_json(load_file(status_link))["v1"]
        assert ["an error"] == status_v1["init-local"]["errors"]
        assert "SomeDatasource" == status_v1["datasource"]
        assert False is os.path.exists(
            data_d.join("result.json")), "unexpected result.json found"
        assert False is os.path.exists(
            link_d.join("result.json")), "unexpected result.json link found"
示例#3
0
    def test_status_wrapper_errors(self, action, name, match, caplog, tmpdir):
        data_d = tmpdir.join("data")
        link_d = tmpdir.join("link")
        FakeArgs = namedtuple("FakeArgs", ["action", "local", "mode"])

        def myaction():
            raise Exception("Should not call myaction")

        myargs = FakeArgs((action, myaction), False, "bogusmode")
        with pytest.raises(ValueError, match=match):
            cli.status_wrapper(name, myargs, data_d, link_d)
        assert "Should not call myaction" not in caplog.text
示例#4
0
    def test_status_wrapper_errors_on_invalid_modes(self):
        """status_wrapper will error if a parameter combination is invalid."""
        tmpd = self.tmp_dir()
        data_d = self.tmp_path('data', tmpd)
        link_d = self.tmp_path('link', tmpd)
        FakeArgs = namedtuple('FakeArgs', ['action', 'local', 'mode'])

        def myaction():
            raise Exception('Should not call myaction')

        myargs = FakeArgs(('modules_name', myaction), False, 'bogusmode')
        with self.assertRaises(ValueError) as cm:
            cli.status_wrapper('modules', myargs, data_d, link_d)
        self.assertEqual(
            "Invalid cloud init mode specified 'modules-bogusmode'",
            str(cm.exception))
        self.assertNotIn('Should not call myaction', self.logs.getvalue())
示例#5
0
    def test_status_wrapper_errors_on_invalid_name(self):
        """status_wrapper will error when the name parameter is not valid.

        Valid name values are only init and modules.
        """
        tmpd = self.tmp_dir()
        data_d = self.tmp_path('data', tmpd)
        link_d = self.tmp_path('link', tmpd)
        FakeArgs = namedtuple('FakeArgs', ['action', 'local', 'mode'])

        def myaction():
            raise Exception('Should not call myaction')

        myargs = FakeArgs(('doesnotmatter', myaction), False, 'bogusmode')
        with self.assertRaises(ValueError) as cm:
            cli.status_wrapper('init1', myargs, data_d, link_d)
        self.assertEqual('unknown name: init1', str(cm.exception))
        self.assertNotIn('Should not call myaction', self.logs.getvalue())
示例#6
0
    def test_status_wrapper_errors_on_invalid_modes(self):
        """status_wrapper will error if a parameter combination is invalid."""
        tmpd = self.tmp_dir()
        data_d = self.tmp_path("data", tmpd)
        link_d = self.tmp_path("link", tmpd)
        FakeArgs = namedtuple("FakeArgs", ["action", "local", "mode"])

        def myaction():
            raise Exception("Should not call myaction")

        myargs = FakeArgs(("modules_name", myaction), False, "bogusmode")
        with self.assertRaises(ValueError) as cm:
            cli.status_wrapper("modules", myargs, data_d, link_d)
        self.assertEqual(
            "Invalid cloud init mode specified 'modules-bogusmode'",
            str(cm.exception),
        )
        self.assertNotIn("Should not call myaction", self.logs.getvalue())
示例#7
0
    def test_status_wrapper_errors_on_invalid_name(self):
        """status_wrapper will error when the name parameter is not valid.

        Valid name values are only init and modules.
        """
        tmpd = self.tmp_dir()
        data_d = self.tmp_path("data", tmpd)
        link_d = self.tmp_path("link", tmpd)
        FakeArgs = namedtuple("FakeArgs", ["action", "local", "mode"])

        def myaction():
            raise Exception("Should not call myaction")

        myargs = FakeArgs(("doesnotmatter", myaction), False, "bogusmode")
        with self.assertRaises(ValueError) as cm:
            cli.status_wrapper("init1", myargs, data_d, link_d)
        self.assertEqual("unknown name: init1", str(cm.exception))
        self.assertNotIn("Should not call myaction", self.logs.getvalue())
示例#8
0
    def test_status_wrapper_init_local_honor_cloud_dir(self, mocker, tmpdir):
        """When running in init-local mode, status_wrapper honors cloud_dir."""
        cloud_dir = tmpdir.join("cloud")
        paths = helpers.Paths({"cloud_dir": str(cloud_dir)})
        mocker.patch(M_PATH + "read_cfg_paths", return_value=paths)
        data_d = cloud_dir.join("data")
        link_d = tmpdir.join("link")

        FakeArgs = namedtuple("FakeArgs", ["action", "local", "mode"])

        def myaction(name, args):
            # Return an error to watch status capture them
            return "SomeDatasource", ["an_error"]

        myargs = FakeArgs(("ignored_name", myaction), True, "bogusmode")
        cli.status_wrapper("init", myargs, link_d=link_d)  # No explicit data_d
        # Access cloud_dir directly
        status_v1 = load_json(load_file(data_d.join("status.json")))["v1"]
        assert ["an_error"] == status_v1["init-local"]["errors"]
        assert "SomeDatasource" == status_v1["datasource"]
        assert False is os.path.exists(
            data_d.join("result.json")), "unexpected result.json found"
        assert False is os.path.exists(
            link_d.join("result.json")), "unexpected result.json link found"