示例#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 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'",
             }))
示例#3
0
文件: env.py 项目: miz-take/pcs
 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,
     )
示例#4
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'
         }))
示例#5
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'
         }))
示例#6
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")
示例#7
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")
示例#8
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"]))
示例#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 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)
示例#11
0
 def test_noexistent_can_be_silenced(self, _):
     RealFile("some role",
              "/path/to.file").remove(silence_no_existence=True)
示例#12
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")
示例#13
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())