コード例 #1
0
    def setUp(self):
        self.test_dir = os.path.join(tempfile.mkdtemp(), self.BASE_TEMP_DIR)
        services.register(ServiceName.AGENT_CONFIG, MagicMock())
        self.image_manager = ImageManager(MagicMock(), MagicMock())
        self.vm_manager = MagicMock()
        self.image_sweeper = DatastoreImageSweeper(self.image_manager,
                                                   self.DATASTORE_ID)
        self.image_sweeper._task_runner = MagicMock()
        self.image_sweeper._task_runner.is_stopped.return_value = False
        self.delete_count = 0

        # Create various image directories and empty vmdks
        dir0 = os.path.join(self.test_dir, self.DATASTORE_ID, "image_")
        self.dir0 = dir0

        # Image dir with correct timestamp file
        image_id_1 = str(uuid.uuid4())
        dir1 = self.create_dir(image_id_1)
        open(os.path.join(dir1, self.IMAGE_TIMESTAMP_FILENAME), 'w').close()

        # Image dir without the correct timestamp file
        image_id_2 = str(uuid.uuid4())
        dir2 = self.create_dir(image_id_2)

        # Image dir with correct timestamp file
        # and with tombstone file
        image_id_3 = str(uuid.uuid4())
        dir3 = self.create_dir(image_id_3)
        open(os.path.join(dir3, self.IMAGE_TIMESTAMP_FILENAME), 'w').close()

        self.image_ids = ["", image_id_1, image_id_2, image_id_3]
        self.image_dirs = ["", dir1, dir2, dir3]
コード例 #2
0
    def setUp(self):
        self.test_dir = os.path.join(tempfile.mkdtemp(), self.BASE_TEMP_DIR)
        services.register(ServiceName.AGENT_CONFIG, MagicMock())
        self.image_manager = EsxImageManager(MagicMock(), MagicMock())
        self.vm_manager = MagicMock()
        self.image_sweeper = DatastoreImageSweeper(self.image_manager,
                                                   self.DATASTORE_ID)
        self.image_sweeper._task_runner = MagicMock()
        self.image_sweeper._task_runner.is_stopped.return_value = False
        self.delete_count = 0

        # Create various image directories and empty vmdks
        dir0 = os.path.join(self.test_dir, self.DATASTORE_ID, "image_")
        self.dir0 = dir0

        # Image dir with correct timestamp file
        image_id_1 = str(uuid.uuid4())
        dir1 = self.create_dir(image_id_1)
        open(os.path.join(dir1, self.IMAGE_TIMESTAMP_FILENAME), 'w').close()

        # Image dir without the correct timestamp file
        image_id_2 = str(uuid.uuid4())
        dir2 = self.create_dir(image_id_2)

        # Image dir with correct timestamp file
        # and with tombstone file
        image_id_3 = str(uuid.uuid4())
        dir3 = self.create_dir(image_id_3)
        open(os.path.join(
            dir3, self.IMAGE_TIMESTAMP_FILENAME), 'w').close()

        self.image_ids = ["", image_id_1, image_id_2, image_id_3]
        self.image_dirs = ["", dir1, dir2, dir3]
コード例 #3
0
    def setUp(self):
        self.test_dir = os.path.join(tempfile.mkdtemp(), self.BASE_TEMP_DIR)
        services.register(ServiceName.AGENT_CONFIG, MagicMock())
        self.vim_client = MagicMock()
        self.vim_client.delete_file.side_effect = self.patched_delete
        self.image_manager = ImageManager(self.vim_client, MagicMock())
        self.vm_manager = MagicMock()
        self.image_sweeper = DatastoreImageSweeper(self.image_manager, self.DATASTORE_ID)
        self.deleted = False
        self.marker_unlinked = False

        # Create various image directories and empty vmdks
        image_id_1 = str(uuid.uuid4())
        image_id_2 = str(uuid.uuid4())
        image_id_3 = str(uuid.uuid4())
        image_id_4 = str(uuid.uuid4())

        self.image_id_1 = image_id_1
        self.image_id_2 = image_id_2
        self.image_id_3 = image_id_3
        self.image_id_4 = image_id_4

        dir1 = os.path.join(self.test_dir, "image_" + image_id_1)
        os.makedirs(dir1)
        dir2 = os.path.join(self.test_dir, "image_" + image_id_2)
        os.makedirs(dir2)
        dir3 = os.path.join(self.test_dir, "image_" + image_id_3)
        os.makedirs(dir3)
        dir4 = os.path.join(self.test_dir, "image_" + image_id_4)
        os.makedirs(dir4)

        self.marker_file_content_time = 0
        self.timestamp_file_mod_time = 0

        # Create a good image vmdk under image_id_1, also create a valid image marker file and a valid timestamp file
        vmdk_filename = image_id_1 + ".vmdk"
        open(os.path.join(dir1, vmdk_filename), 'w').close()
        timestamp_filename = os.path.join(dir1, self.IMAGE_TIMESTAMP_FILENAME)
        open(timestamp_filename, 'w').close()
        marker_filename = os.path.join(dir1, self.IMAGE_MARKER_FILENAME)
        open(marker_filename, 'w').close()

        # Create a good image vmdk under image_id_2, create timestamp but no image marker file,
        vmdk_filename = image_id_2 + ".vmdk"
        open(os.path.join(dir2, vmdk_filename), 'w').close()
        timestamp_filename = os.path.join(dir2, self.IMAGE_TIMESTAMP_FILENAME)
        open(timestamp_filename, 'w').close()

        # Create a good image vmdk under image_id_3, create image_marker file but no timestamp file
        vmdk_filename = image_id_3 + ".vmdk"
        open(os.path.join(dir3, vmdk_filename), 'w').close()
        marker_filename = os.path.join(dir3, self.IMAGE_MARKER_FILENAME)
        open(marker_filename, 'w').close()

        # Create a good image vmdk under image_id_4, create image_marker file, renamed timestamp file
        # but no timestamp file
        vmdk_filename = image_id_4 + ".vmdk"
        open(os.path.join(dir4, vmdk_filename), 'w').close()
        marker_filename = os.path.join(dir4, self.IMAGE_MARKER_FILENAME)
        open(marker_filename, 'w').close()
コード例 #4
0
    def setUp(self):
        self.test_dir = os.path.join(tempfile.mkdtemp(), self.BASE_TEMP_DIR)
        services.register(ServiceName.AGENT_CONFIG, MagicMock())
        self.vim_client = MagicMock()
        self.vim_client.delete_file.side_effect = self.patched_delete
        self.image_manager = ImageManager(self.vim_client, MagicMock())
        self.vm_manager = MagicMock()
        self.image_sweeper = DatastoreImageSweeper(self.image_manager, self.DATASTORE_ID)
        self.deleted = False
        self.marker_unlinked = False

        # Create various image directories and empty vmdks
        image_id_1 = str(uuid.uuid4())
        image_id_2 = str(uuid.uuid4())
        image_id_3 = str(uuid.uuid4())
        image_id_4 = str(uuid.uuid4())

        self.image_id_1 = image_id_1
        self.image_id_2 = image_id_2
        self.image_id_3 = image_id_3
        self.image_id_4 = image_id_4

        dir1 = os.path.join(self.test_dir, "image_" + image_id_1)
        os.makedirs(dir1)
        dir2 = os.path.join(self.test_dir, "image_" + image_id_2)
        os.makedirs(dir2)
        dir3 = os.path.join(self.test_dir, "image_" + image_id_3)
        os.makedirs(dir3)
        dir4 = os.path.join(self.test_dir, "image_" + image_id_4)
        os.makedirs(dir4)

        self.marker_file_content_time = 0
        self.timestamp_file_mod_time = 0

        # Create a good image vmdk under image_id_1, also create a valid image marker file and a valid timestamp file
        vmdk_filename = image_id_1 + ".vmdk"
        open(os.path.join(dir1, vmdk_filename), 'w').close()
        timestamp_filename = os.path.join(dir1, self.IMAGE_TIMESTAMP_FILENAME)
        open(timestamp_filename, 'w').close()
        marker_filename = os.path.join(dir1, self.IMAGE_MARKER_FILENAME)
        open(marker_filename, 'w').close()

        # Create a good image vmdk under image_id_2, create timestamp but no image marker file,
        vmdk_filename = image_id_2 + ".vmdk"
        open(os.path.join(dir2, vmdk_filename), 'w').close()
        timestamp_filename = os.path.join(dir2, self.IMAGE_TIMESTAMP_FILENAME)
        open(timestamp_filename, 'w').close()

        # Create a good image vmdk under image_id_3, create image_marker file but no timestamp file
        vmdk_filename = image_id_3 + ".vmdk"
        open(os.path.join(dir3, vmdk_filename), 'w').close()
        marker_filename = os.path.join(dir3, self.IMAGE_MARKER_FILENAME)
        open(marker_filename, 'w').close()

        # Create a good image vmdk under image_id_4, create image_marker file, renamed timestamp file
        # but no timestamp file
        vmdk_filename = image_id_4 + ".vmdk"
        open(os.path.join(dir4, vmdk_filename), 'w').close()
        marker_filename = os.path.join(dir4, self.IMAGE_MARKER_FILENAME)
        open(marker_filename, 'w').close()
コード例 #5
0
    def setUp(self):
        self.test_dir = os.path.join(tempfile.mkdtemp(), self.BASE_TEMP_DIR)
        services.register(ServiceName.AGENT_CONFIG, MagicMock())
        self.image_manager = EsxImageManager(MagicMock(), MagicMock())
        self.vm_manager = MagicMock()
        self.image_sweeper = DatastoreImageSweeper(self.image_manager,
                                                   self.DATASTORE_ID)
        self.image_sweeper._task_runner = MagicMock()
        self.image_sweeper._task_runner.is_stopped.return_value = False
        self.delete_count = 0

        # Create various image directories and empty vmdks
        dir0 = os.path.join(self.test_dir, "images/im")
        image_id_1 = str(uuid.uuid4())
        image_id_2 = str(uuid.uuid4())
        image_id_3 = str(uuid.uuid4())
        image_id_4 = "invalid_image_id"
        self.image_ids = ["", image_id_1, image_id_2,
                          image_id_3, image_id_4]
        dir1 = os.path.join(dir0, image_id_1)
        os.makedirs(dir1)
        dir2 = os.path.join(dir0, image_id_2)
        os.makedirs(dir2)
        dir3 = os.path.join(dir0, image_id_3)
        os.makedirs(dir3)
        dir4 = os.path.join(dir0, image_id_4)
        os.makedirs(dir4)

        # Create a vmdk under "im", since the image_id is
        # not a valid uuid it should be skipped
        open(os.path.join(dir0, "im.vmdk"), 'w').close()

        # Create a good image vmdk under image_id_1 but
        # no image marker file, this should not be deleted
        vmdk_filename = image_id_1 + ".vmdk"
        open(os.path.join(dir1, vmdk_filename), 'w').close()

        # Create a good image vmdk under image_id_2, also create
        # an unused image marker file, image_id_2 should be
        # deleted
        vmdk_filename = image_id_2 + ".vmdk"
        open(os.path.join(dir2, vmdk_filename), 'w').close()
        open(os.path.join(
            dir2, self.IMAGE_MARKER_FILENAME), 'w').close()

        # Create a marker file under dir3 but no
        # vmdk file. It should be deleted as well
        open(os.path.join(
            dir3, self.IMAGE_MARKER_FILENAME), 'w').close()

        # Create a vmdk under an invalid image directory,
        # also create a marker file. Since the image_id
        # is not valid it should not be deleted
        vmdk_filename = image_id_4 + ".vmdk"
        open(os.path.join(dir4, vmdk_filename), 'w').close()
        open(os.path.join(
            dir4, self.IMAGE_MARKER_FILENAME), 'w').close()
コード例 #6
0
 def setUp(self, connect, creds):
     self.shadow_vm_id = SHADOW_VM_NAME_PREFIX + str(uuid.uuid4())
     self.image_datastores = ["image_ds", "alt_image_ds"]
     creds.return_value = ["username", "password"]
     self.vim_client = VimClient(auto_sync=False)
     self.patcher = patch("host.hypervisor.esx.vm_config.GetEnv")
     self.patcher.start()
     services.register(ServiceName.AGENT_CONFIG, MagicMock())
     self.http_transferer = HttpNfcTransferer(self.vim_client,
                                              self.image_datastores)
コード例 #7
0
 def setUp(self, connect, creds):
     self.shadow_vm_id = SHADOW_VM_NAME_PREFIX + str(uuid.uuid1())
     self.image_datastores = ["image_ds", "alt_image_ds"]
     creds.return_value = ["username", "password"]
     self.vim_client = VimClient(auto_sync=False)
     self.patcher = patch("host.hypervisor.esx.vm_config.GetEnv")
     self.patcher.start()
     services.register(ServiceName.AGENT_CONFIG, MagicMock())
     self.http_transferer = HttpNfcTransferer(self.vim_client,
                                              self.image_datastores)
コード例 #8
0
    def setUp(self):
        self.test_dir = os.path.join(tempfile.mkdtemp(), self.BASE_TEMP_DIR)
        services.register(ServiceName.AGENT_CONFIG, MagicMock())
        self.image_manager = EsxImageManager(MagicMock(), MagicMock())
        self.vm_manager = MagicMock()
        self.image_scanner = DatastoreImageScanner(self.image_manager,
                                                   self.vm_manager,
                                                   self.DATASTORE_ID)
        self.image_scanner._task_runner = MagicMock()
        self.image_scanner._task_runner.is_stopped.return_value = False
        self.write_count = 0

        # Create various image directories and empty vmdks
        dir0 = os.path.join(self.test_dir, "images/im")

        image_id_1 = str(uuid.uuid4())
        image_id_2 = str(uuid.uuid4())
        image_id_3 = str(uuid.uuid4())
        image_id_4 = "invalid_image_id"
        self.image_ids = ["", image_id_1, image_id_2,
                          image_id_3, image_id_4]
        dir1 = os.path.join(dir0, image_id_1)
        os.makedirs(dir1)
        dir2 = os.path.join(dir0, image_id_2)
        os.makedirs(dir2)
        dir3 = os.path.join(dir0, image_id_3)
        os.makedirs(dir3)
        dir4 = os.path.join(dir0, image_id_4)
        os.makedirs(dir4)
        # Create a vmdk under "im", since the image_id is
        # not a valid uuid it should be skipped
        open(os.path.join(dir0, "im.vmdk"), 'w').close()
        # Create a good image vmdk under image_id_1, the name
        # of the vmdk matches the directory that contains it
        # so this is a valid image to remove
        vmdk_filename = image_id_1 + ".vmdk"
        open(os.path.join(dir1, vmdk_filename), 'w').close()
        # Create a good image vmdk under image_id_2, also create
        # an unused image marker file, image_id_2 should also be
        # included in the list of images to remove
        vmdk_filename = image_id_2 + ".vmdk"
        open(os.path.join(dir2, vmdk_filename), 'w').close()
        open(
            os.path.join(
                dir2,
                self.image_manager.IMAGE_MARKER_FILE_NAME),
            'w').close()
        # Don't create anything under directory dir3
        # it should still mark the image as deletable

        # Create a vmdk under an invalid image directory, since
        # the image id is not valid it should not mark it
        # for deletion
        vmdk_filename = image_id_4 + ".vmdk"
        open(os.path.join(dir4, vmdk_filename), 'w').close()
コード例 #9
0
 def setUp(self, connect, creds):
     self.host_uuid = str(uuid.uuid4())
     VimClient.host_uuid = self.host_uuid
     self.image_ds = "image_ds"
     creds.return_value = ["username", "password"]
     self.vim_client = VimClient(auto_sync=False)
     self.patcher = patch("host.hypervisor.esx.vm_config.GetEnv")
     self.patcher.start()
     services.register(ServiceName.AGENT_CONFIG, MagicMock())
     self.http_transferer = HttpNfcTransferer(self.vim_client,
                                              self.image_ds)
コード例 #10
0
    def setUp(self):
        self.test_dir = os.path.join(tempfile.mkdtemp(), self.BASE_TEMP_DIR)
        services.register(ServiceName.AGENT_CONFIG, MagicMock())
        self.image_manager = EsxImageManager(MagicMock(), MagicMock())
        self.vm_manager = MagicMock()
        self.image_sweeper = DatastoreImageSweeper(self.image_manager,
                                                   self.DATASTORE_ID)
        self.image_sweeper._task_runner = MagicMock()
        self.image_sweeper._task_runner.is_stopped.return_value = False
        self.delete_count = 0

        # Create various image directories and empty vmdks
        dir0 = os.path.join(self.test_dir, "images/im")
        image_id_1 = str(uuid.uuid4())
        image_id_2 = str(uuid.uuid4())
        image_id_3 = str(uuid.uuid4())
        image_id_4 = "invalid_image_id"
        self.image_ids = ["", image_id_1, image_id_2, image_id_3, image_id_4]
        dir1 = os.path.join(dir0, image_id_1)
        os.makedirs(dir1)
        dir2 = os.path.join(dir0, image_id_2)
        os.makedirs(dir2)
        dir3 = os.path.join(dir0, image_id_3)
        os.makedirs(dir3)
        dir4 = os.path.join(dir0, image_id_4)
        os.makedirs(dir4)

        # Create a vmdk under "im", since the image_id is
        # not a valid uuid it should be skipped
        open(os.path.join(dir0, "im.vmdk"), 'w').close()

        # Create a good image vmdk under image_id_1 but
        # no image marker file, this should not be deleted
        vmdk_filename = image_id_1 + ".vmdk"
        open(os.path.join(dir1, vmdk_filename), 'w').close()

        # Create a good image vmdk under image_id_2, also create
        # an unused image marker file, image_id_2 should be
        # deleted
        vmdk_filename = image_id_2 + ".vmdk"
        open(os.path.join(dir2, vmdk_filename), 'w').close()
        open(os.path.join(dir2, self.IMAGE_MARKER_FILENAME), 'w').close()

        # Create a marker file under dir3 but no
        # vmdk file. It should be deleted as well
        open(os.path.join(dir3, self.IMAGE_MARKER_FILENAME), 'w').close()

        # Create a vmdk under an invalid image directory,
        # also create a marker file. Since the image_id
        # is not valid it should not be deleted
        vmdk_filename = image_id_4 + ".vmdk"
        open(os.path.join(dir4, vmdk_filename), 'w').close()
        open(os.path.join(dir4, self.IMAGE_MARKER_FILENAME), 'w').close()
コード例 #11
0
    def setUp(self):
        self.test_dir = os.path.join(tempfile.mkdtemp(), self.BASE_TEMP_DIR)
        services.register(ServiceName.AGENT_CONFIG, MagicMock())
        self.image_manager = EsxImageManager(MagicMock(), MagicMock())
        self.vm_manager = MagicMock()
        self.image_scanner = DatastoreImageScanner(self.image_manager,
                                                   self.vm_manager,
                                                   self.DATASTORE_ID)
        self.image_scanner._task_runner = MagicMock()
        self.image_scanner._task_runner.is_stopped.return_value = False
        self.write_count = 0

        # Create various image directories and empty vmdks
        dir0 = os.path.join(self.test_dir, "images/im")

        image_id_1 = str(uuid.uuid4())
        image_id_2 = str(uuid.uuid4())
        image_id_3 = str(uuid.uuid4())
        image_id_4 = "invalid_image_id"
        self.image_ids = ["", image_id_1, image_id_2, image_id_3, image_id_4]
        dir1 = os.path.join(dir0, image_id_1)
        os.makedirs(dir1)
        dir2 = os.path.join(dir0, image_id_2)
        os.makedirs(dir2)
        dir3 = os.path.join(dir0, image_id_3)
        os.makedirs(dir3)
        dir4 = os.path.join(dir0, image_id_4)
        os.makedirs(dir4)
        # Create a vmdk under "im", since the image_id is
        # not a valid uuid it should be skipped
        open(os.path.join(dir0, "im.vmdk"), 'w').close()
        # Create a good image vmdk under image_id_1, the name
        # of the vmdk matches the directory that contains it
        # so this is a valid image to remove
        vmdk_filename = image_id_1 + ".vmdk"
        open(os.path.join(dir1, vmdk_filename), 'w').close()
        # Create a good image vmdk under image_id_2, also create
        # an unused image marker file, image_id_2 should also be
        # included in the list of images to remove
        vmdk_filename = image_id_2 + ".vmdk"
        open(os.path.join(dir2, vmdk_filename), 'w').close()
        open(os.path.join(dir2, self.image_manager.IMAGE_MARKER_FILE_NAME),
             'w').close()
        # Don't create anything under directory dir3
        # it should still mark the image as deletable

        # Create a vmdk under an invalid image directory, since
        # the image id is not valid it should not mark it
        # for deletion
        vmdk_filename = image_id_4 + ".vmdk"
        open(os.path.join(dir4, vmdk_filename), 'w').close()
コード例 #12
0
    def setUp(self):
        # Create VM manager
        self.vim_client = VimClient(auto_sync=False)
        self.vim_client._content = MagicMock()
        self.vim_client.wait_for_task = MagicMock()
        self.vm_manager = VmManager(self.vim_client, MagicMock())
        services.register(ServiceName.AGENT_CONFIG, MagicMock())

        # Set up test files
        self.base_dir = os.path.dirname(__file__)
        self.test_dir = os.path.join(self.base_dir, "../test_files")
        self.image_manager = ImageManager(MagicMock(), MagicMock())
        self.image_scanner = DatastoreImageScanner(self.image_manager, self.vm_manager, self.DATASTORE_ID)
        self.write_count = 0
コード例 #13
0
    def setUp(self):
        # Create VM manager
        self.vim_client = VimClient(auto_sync=False)
        self.vim_client._content = MagicMock()
        self.vim_client.wait_for_task = MagicMock()
        self.vm_manager = VmManager(self.vim_client, MagicMock())
        services.register(ServiceName.AGENT_CONFIG, MagicMock())

        # Set up test files
        self.base_dir = os.path.dirname(__file__)
        self.test_dir = os.path.join(self.base_dir, "../test_files")
        self.image_manager = ImageManager(MagicMock(), MagicMock())
        self.image_scanner = DatastoreImageScanner(self.image_manager, self.vm_manager, self.DATASTORE_ID)
        self.write_count = 0
コード例 #14
0
    def setUp(self, connect, update, creds):
        # Create VM manager
        creds.return_value = ["username", "password"]
        self.vim_client = VimClient(auto_sync=False)
        self.vim_client.wait_for_task = MagicMock()
        self.patcher = patch("host.hypervisor.esx.vm_config.GetEnv")
        self.patcher.start()
        self.vm_manager = EsxVmManager(self.vim_client, MagicMock())
        services.register(ServiceName.AGENT_CONFIG, MagicMock())

        # Set up test files
        self.base_dir = os.path.dirname(__file__)
        self.test_dir = os.path.join(self.base_dir, "../../test_files")
        self.image_manager = EsxImageManager(MagicMock(), MagicMock())
        self.image_scanner = DatastoreImageScanner(self.image_manager,
                                                   self.vm_manager,
                                                   self.DATASTORE_ID)
        self.write_count = 0
コード例 #15
0
 def setUp(self):
     self.vim_client = VimClient(auto_sync=False)
     self.vim_client._content = MagicMock()
     self.ds_manager = MagicMock()
     services.register(ServiceName.AGENT_CONFIG, MagicMock())
     self.image_manager = ImageManager(self.vim_client, self.ds_manager)
コード例 #16
0
 def setUp(self, connect, update, creds):
     creds.return_value = ["username", "password"]
     self.vim_client = VimClient(auto_sync=False)
     self.ds_manager = MagicMock()
     services.register(ServiceName.AGENT_CONFIG, MagicMock())
     self.image_manager = EsxImageManager(self.vim_client, self.ds_manager)
コード例 #17
0
 def setUp(self, connect, update, creds):
     creds.return_value = ["username", "password"]
     self.vim_client = VimClient(auto_sync=False)
     self.ds_manager = MagicMock()
     services.register(ServiceName.AGENT_CONFIG, MagicMock())
     self.image_manager = EsxImageManager(self.vim_client, self.ds_manager)