Пример #1
0
 def __set_key_path(self, path):
     self.__key_path = path
     self.__key = RealFile(
         file_role=env_file_role_codes.BOOTH_KEY,
         file_path=path,
         is_binary=True
     )
Пример #2
0
 def __init__(self):
     """
     callable get_cib should return cib as lxml tree
     """
     self.__authkey = RealFile(
         file_role=env_file_role_codes.PACEMAKER_AUTHKEY,
         file_path=settings.pacemaker_authkey_file,
     )
Пример #3
0
Файл: env.py Проект: idevat/pcs
 def __init__(self, report_processor, env_data):
     self.__report_processor = report_processor
     self.__name = env_data["name"]
     if "config_file" in env_data:
         self.__config = GhostFile(
             file_role=env_file_role_codes.BOOTH_CONFIG, content=env_data["config_file"]["content"]
         )
         self.__key_path = env_data["key_path"]
         self.__key = GhostFile(file_role=env_file_role_codes.BOOTH_KEY, content=env_data["key_file"]["content"])
     else:
         self.__config = RealFile(
             file_role=env_file_role_codes.BOOTH_CONFIG, file_path=get_config_file_name(env_data["name"])
         )
         self.__set_key_path(get_key_path(env_data["name"]))
Пример #4
0
 def __init__(self, report_processor, env_data):
     self.__report_processor = report_processor
     self.__name = env_data["name"]
     if "config_file" in env_data:
         self.__config = GhostFile(
             file_role=env_file_role_codes.BOOTH_CONFIG,
             content=env_data["config_file"]["content"])
         self.__key_path = env_data["key_path"]
         self.__key = GhostFile(file_role=env_file_role_codes.BOOTH_KEY,
                                content=env_data["key_file"]["content"])
     else:
         self.__config = RealFile(
             file_role=env_file_role_codes.BOOTH_CONFIG,
             file_path=get_config_file_name(env_data["name"]),
         )
         self.__set_key_path(get_key_path(env_data["name"]))
Пример #5
0
 def __set_key_path(self, path):
     self.__key_path = path
     self.__key = RealFile(
         file_role=env_file_role_codes.BOOTH_KEY,
         file_path=path,
         is_binary=True
     )
Пример #6
0
 def test_raises_when_could_not_write(self):
     assert_raise_library_error(
         lambda: RealFile("some role", "/no/existing/file.path").write(
             ["content"]), (severities.ERROR, report_codes.FILE_IO_ERROR, {
                 "reason":
                 "No such file or directory: '/no/existing/file.path'",
             }))
Пример #7
0
 def test_existence_is_required(self, _):
     assert_raise_library_error(
         lambda: RealFile("some role", "/path/to.file").remove(),
         (severities.ERROR, report_codes.FILE_IO_ERROR, {
             'reason': "File does not exist",
             'file_role': 'some role',
             'file_path': '/path/to.file'
         }))
Пример #8
0
 def test_raise_library_error_when_remove_failed(self, _, dummy):
     assert_raise_library_error(
         lambda: RealFile("some role", "/path/to.file").remove(),
         (severities.ERROR, report_codes.FILE_IO_ERROR, {
             'reason': "mock remove failed: '/path/to.file'",
             'file_role': 'some role',
             'file_path': '/path/to.file'
         }))
Пример #9
0
 def __init__(self, report_processor, env_data):
     self.__report_processor = report_processor
     self.__name = (env_data["name"]
                    if env_data["name"] is not None else DEFAULT_BOOTH_NAME)
     if "config_file" in env_data:
         self.__config = GhostFile(
             file_role=env_file_role_codes.BOOTH_CONFIG,
             content=env_data["config_file"]["content"])
         self.__key_path = env_data["key_path"]
         self.__key = GhostFile(file_role=env_file_role_codes.BOOTH_KEY,
                                content=env_data["key_file"]["content"],
                                is_binary=True)
     else:
         self.__config = RealFile(
             file_role=env_file_role_codes.BOOTH_CONFIG,
             file_path=get_config_file_name(self.name),
         )
         self.__set_key_path(get_key_path(self.name))
Пример #10
0
 def __init__(self):
     """
     callable get_cib should return cib as lxml tree
     """
     self.__authkey = RealFile(
         file_role=env_file_role_codes.PACEMAKER_AUTHKEY,
         file_path=settings.pacemaker_authkey_file,
         is_binary=True,
     )
Пример #11
0
 def test_success_write_content_to_path(self):
     mock_open = mock.mock_open()
     mock_file_operation = mock.Mock()
     with mock.patch("pcs.lib.env_file.open", mock_open, create=True):
         RealFile("some role", "/etc/booth/some-name.conf").write(
             "config content", file_operation=mock_file_operation)
         mock_open.assert_called_once_with("/etc/booth/some-name.conf", "w")
         mock_open().write.assert_called_once_with("config content")
         mock_file_operation.assert_called_once_with(
             "/etc/booth/some-name.conf")
Пример #12
0
 def test_success_binary(self):
     mock_open = mock.mock_open()
     mock_file_operation = mock.Mock()
     with mock.patch("pcs.lib.env_file.open", mock_open, create=True):
         RealFile("some role", "/etc/booth/some-name.conf").write(
             "config content".encode("utf-8"),
             file_operation=mock_file_operation,
             is_binary=True)
         mock_open.assert_called_once_with("/etc/booth/some-name.conf",
                                           "wb")
         mock_open().write.assert_called_once_with(
             "config content".encode("utf-8"))
         mock_file_operation.assert_called_once_with(
             "/etc/booth/some-name.conf")
Пример #13
0
 def __init__(self, report_processor, env_data):
     self.__report_processor = report_processor
     self.__name = (
         env_data["name"]
         if env_data["name"] is not None
         else DEFAULT_BOOTH_NAME
     )
     if "config_file" in env_data:
         self.__config = GhostFile(
             file_role=env_file_role_codes.BOOTH_CONFIG,
             content=env_data["config_file"]["content"]
         )
         self.__key_path = env_data["key_path"]
         self.__key = GhostFile(
             file_role=env_file_role_codes.BOOTH_KEY,
             content=env_data["key_file"]["content"],
             is_binary=True
         )
     else:
         self.__config = RealFile(
             file_role=env_file_role_codes.BOOTH_CONFIG,
             file_path=get_config_file_name(self.name),
         )
         self.__set_key_path(get_key_path(self.name))
Пример #14
0
class PacemakerEnv(object):
    def __init__(self):
        """
        callable get_cib should return cib as lxml tree
        """
        self.__authkey = RealFile(
            file_role=env_file_role_codes.PACEMAKER_AUTHKEY,
            file_path=settings.pacemaker_authkey_file,
        )

    @property
    def has_authkey(self):
        return self.__authkey.exists

    def get_authkey_content(self):
        return self.__authkey.read()
Пример #15
0
class PacemakerEnv:
    def __init__(self):
        """
        callable get_cib should return cib as lxml tree
        """
        self.__authkey = RealFile(
            file_role=env_file_role_codes.PACEMAKER_AUTHKEY,
            file_path=settings.pacemaker_authkey_file,
            is_binary=True,
        )

    @property
    def has_authkey(self):
        return self.__authkey.exists

    def get_authkey_content(self):
        return self.__authkey.read()
Пример #16
0
 def test_success_read_content_from_file(self):
     mock_open = mock.mock_open()
     with mock.patch("pcs.lib.env_file.open", mock_open, create=True):
         mock_open().read.return_value = "test booth\nconfig"
         self.assertEqual("test booth\nconfig",
                          RealFile("some role", "/path/to.file").read())
Пример #17
0
 def test_success_remove_file(self, _, mock_remove):
     RealFile("some role", "/path/to.file").remove()
     mock_remove.assert_called_once_with("/path/to.file")
Пример #18
0
 def test_noexistent_can_be_silenced(self, _):
     RealFile("some role",
              "/path/to.file").remove(silence_no_existence=True)
Пример #19
0
 def check(self, report_processor, can_overwrite_existing=False):
     real_file = RealFile("some role", "/etc/booth/some-name.conf")
     real_file.assert_no_conflict_with_existing(report_processor,
                                                can_overwrite_existing)
Пример #20
0
class BoothEnv(object):
    def __init__(self, report_processor, env_data):
        self.__report_processor = report_processor
        self.__name = env_data["name"]
        if "config_file" in env_data:
            self.__config = GhostFile(
                file_role=env_file_role_codes.BOOTH_CONFIG,
                content=env_data["config_file"]["content"])
            self.__key_path = env_data["key_path"]
            self.__key = GhostFile(file_role=env_file_role_codes.BOOTH_KEY,
                                   content=env_data["key_file"]["content"],
                                   is_binary=True)
        else:
            self.__config = RealFile(
                file_role=env_file_role_codes.BOOTH_CONFIG,
                file_path=get_config_file_name(env_data["name"]),
            )
            self.__set_key_path(get_key_path(env_data["name"]))

    def __set_key_path(self, path):
        self.__key_path = path
        self.__key = RealFile(file_role=env_file_role_codes.BOOTH_KEY,
                              file_path=path,
                              is_binary=True)

    def command_expect_live_env(self):
        if not self.__config.is_live:
            raise LibraryError(
                common_reports.live_environment_required([
                    "BOOTH_CONF",
                    "BOOTH_KEY",
                ]))

    def set_key_path(self, path):
        if not self.__config.is_live:
            raise AssertionError(
                "Set path of keyfile is supported only in live environment")
        self.__set_key_path(path)

    @property
    def name(self):
        return self.__name

    @property
    def key_path(self):
        return self.__key_path

    def get_config_content(self):
        return self.__config.read()

    def create_config(self, content, can_overwrite_existing=False):
        self.__config.assert_no_conflict_with_existing(self.__report_processor,
                                                       can_overwrite_existing)
        self.__config.write(content)

    def create_key(self, key_content, can_overwrite_existing=False):
        self.__key.assert_no_conflict_with_existing(self.__report_processor,
                                                    can_overwrite_existing)
        self.__key.write(key_content, set_keyfile_access)

    def push_config(self, content):
        self.__config.write(content)

    def remove_key(self):
        self.__key.remove(silence_no_existence=True)

    def remove_config(self):
        self.__config.remove()

    def export(self):
        return {} if self.__config.is_live else {
            "config_file": self.__config.export(),
            "key_file": self.__key.export(),
        }
Пример #21
0
 def check(self, report_processor, can_overwrite_existing=False):
     real_file = RealFile("some role", "/etc/booth/some-name.conf")
     real_file.assert_no_conflict_with_existing(
         report_processor,
         can_overwrite_existing
     )
Пример #22
0
Файл: env.py Проект: idevat/pcs
class BoothEnv(object):
    def __init__(self, report_processor, env_data):
        self.__report_processor = report_processor
        self.__name = env_data["name"]
        if "config_file" in env_data:
            self.__config = GhostFile(
                file_role=env_file_role_codes.BOOTH_CONFIG, content=env_data["config_file"]["content"]
            )
            self.__key_path = env_data["key_path"]
            self.__key = GhostFile(file_role=env_file_role_codes.BOOTH_KEY, content=env_data["key_file"]["content"])
        else:
            self.__config = RealFile(
                file_role=env_file_role_codes.BOOTH_CONFIG, file_path=get_config_file_name(env_data["name"])
            )
            self.__set_key_path(get_key_path(env_data["name"]))

    def __set_key_path(self, path):
        self.__key_path = path
        self.__key = RealFile(file_role=env_file_role_codes.BOOTH_KEY, file_path=path)

    def command_expect_live_env(self):
        if not self.__config.is_live:
            raise LibraryError(common_reports.live_environment_required(["--booth-conf", "--booth-key"]))

    def set_key_path(self, path):
        if not self.__config.is_live:
            raise AssertionError("Set path of keyfile is supported only in live environment")
        self.__set_key_path(path)

    @property
    def name(self):
        return self.__name

    @property
    def key_path(self):
        return self.__key_path

    def get_config_content(self):
        return self.__config.read()

    def create_config(self, content, can_overwrite_existing=False):
        self.__config.assert_no_conflict_with_existing(self.__report_processor, can_overwrite_existing)
        self.__config.write(content)

    def create_key(self, key_content, can_overwrite_existing=False):
        self.__key.assert_no_conflict_with_existing(self.__report_processor, can_overwrite_existing)
        self.__key.write(key_content, set_keyfile_access, is_binary=True)

    def push_config(self, content):
        self.__config.write(content)

    def remove_key(self):
        self.__key.remove(silence_no_existence=True)

    def remove_config(self):
        self.__config.remove()

    def export(self):
        return {} if self.__config.is_live else {"config_file": self.__config.export(), "key_file": self.__key.export()}