def test_storage_create(self, mock_client_get):
        mock_client_get().create_storage.side_effect = [(
            'file name',
            'something'
        )]
        self.mock_ctx.capabilities.get_all.return_value = {
            'vm_inst_id': {
                'name': 'Julie',
                'vsphere_server_id': 'i',
            },
        }

        storage.create(
            storage={
                'storage_size': 7,
            }, use_external_resource=False)

        self.mock_ctx.operation.retry.assert_not_called()
        self.mock_ctx.instance.runtime_properties.__setitem__.assert_has_calls(
            [
                call('scsi_id', 'something'),
                call('datastore_file_name', 'file name'),
                call('attached_vm_id', 'i'),
                call('attached_vm_name', 'Julie'),

            ]
        )
Beispiel #2
0
    def test_storage_create_external(self, mock_client_get):
        mock_client_get().create_storage.side_effect = [(
            'file name',
            'something'
        )]

        self.mock_ctx.capabilities.get_all = Mock(return_value={
            'vm_inst_id': {
                'name': 'Julie',
                'vsphere_server_id': 'i',
            },
        })

        # not enough info
        with self.assertRaises(NonRecoverableError):
            storage.create(
                storage={
                    'storage_size': 7,
                }, use_external_resource=True)

        storage.create(
            storage={
                'scsi_id': 'something',
                'datastore_file_name': 'file name',
                'storage_size': 7,
            }, use_external_resource=True)

        self.assertEqual(self.mock_ctx.instance.runtime_properties,
                         {'datastore_file_name': 'file name',
                          'storage_size': 7,
                          'scsi_id': 'something',
                          'attached_vm_id': 'i',
                          'attached_vm_name': 'Julie',
                          'use_external_resource': True})
Beispiel #3
0
    def test_storage_create_ignore(self, mock_client_get):
        runtime = self.mock_ctx.instance.runtime_properties
        runtime['scsi_id'] = 'something'
        runtime['datastore_file_name'] = 'file name'
        runtime['storage_image'] = 'file name'
        runtime['attached_vm_id'] = 'i'
        runtime['attached_vm_name'] = 'Julie'

        self.mock_ctx.capabilities.get_all = Mock(return_value={
            'vm_inst_id': {
                'name': 'Julie',
                'vsphere_server_id': 'i',
            },
        })

        storage.create(
            storage={
                'storage_size': 7,
            }, use_external_resource=False)

        mock_client_get().create_storage.assert_not_called()
        self.assertEqual(self.mock_ctx.instance.runtime_properties,
                         {'scsi_id': 'something',
                          'datastore_file_name': 'file name',
                          'storage_image': 'file name',
                          'attached_vm_id': 'i',
                          'attached_vm_name': 'Julie'})
    def test_storage_create_race_retry(self, mock_client_get):
        mock_client_get().create_storage.side_effect = NonRecoverableError(
            'vim.fault.FileAlreadyExists')
        self.mock_ctx.capabilities.get_all.return_value = {
            'vm_inst_id': {
                'name': 'Julie',
                'vsphere_server_id': 'i',
            },
        }

        storage.create(storage={
            'storage_size': 7,
        })

        self.mock_ctx.operation.retry.assert_called_once()
    def test_storage_create_race_retry(self, mock_client_get):
        mock_client_get().create_storage.side_effect = NonRecoverableError(
            'vim.fault.FileAlreadyExists')
        self.mock_ctx.capabilities.get_all.return_value = {
            'vm_inst_id': {
                'name': 'Julie',
                'vsphere_server_id': 'i',
            },
        }

        storage.create(
            storage={
                'storage_size': 7,
            }, use_external_resource=False)

        self.mock_ctx.operation.retry.assert_called_once()
    def test_storage_resize(self):
        vm_id = self.ctx.capabilities.get_all().values()[0][
            server_plugin.VSPHERE_SERVER_ID]
        storage_size = self.ctx.node.properties['storage']['storage_size']
        new_storage_size = storage_size + 1

        storage_plugin.create()

        self.ctx.instance.runtime_properties['storage_size'] = new_storage_size

        storage_plugin.resize()

        storage_file_name = \
            self.ctx.instance.runtime_properties[VSPHERE_STORAGE_FILE_NAME]

        storage = self.assert_storage_exists_and_get(vm_id, storage_file_name)
        self.assertEqual(new_storage_size * 1024**2, storage.capacityInKB)
Beispiel #7
0
    def test_storage_create_race_retry(self, mock_client_get):
        self.mock_ctx.instance.runtime_properties = {}
        mock_client_get().create_storage.side_effect = NonRecoverableError(
            'vim.fault.FileAlreadyExists')
        self.mock_ctx.capabilities.get_all.return_value = {
            'vm_inst_id': {
                'name': 'Julie',
                'vsphere_server_id': 'i',
            },
        }

        storage.create(storage={
            'storage_size': 7,
        },
                       use_external_resource=False)

        self.mock_ctx.operation.retry.assert_called_once()
        self.assertEqual(self.mock_ctx.instance.runtime_properties, {})
Beispiel #8
0
    def test_storage_create_race_nonrecovery(self, mock_client_get):
        mock_client_get().create_storage.side_effect = NonRecoverableError(
            'Something is going wrong')
        self.mock_ctx.capabilities.get_all = Mock(return_value={
            'vm_inst_id': {
                'name': 'Julie',
                'vsphere_server_id': 'i',
            },
        })

        with self.assertRaisesRegexp(
            NonRecoverableError,
            'Something is going wrong'
        ):
            storage.create(
                storage={
                    'storage_size': 7,
                }, use_external_resource=False)

        self.assertFalse(self.mock_ctx.instance.runtime_properties)
Beispiel #9
0
    def test_storage_create_race_retry(self, mock_client_get):
        mock_client_get().create_storage.side_effect = NonRecoverableError(
            'vim.fault.FileAlreadyExists')
        self.mock_ctx.capabilities.get_all = Mock(return_value={
            'vm_inst_id': {
                'name': 'Julie',
                'vsphere_server_id': 'i',
            },
        })

        with self.assertRaisesRegexp(
            OperationRetry,
            'Name clash with another storage. Retrying'
        ):
            storage.create(
                storage={
                    'storage_size': 7,
                }, use_external_resource=False)

        self.assertEqual(self.mock_ctx.instance.runtime_properties, {})
    def test_storage_create_delete(self):
        storage_size = self.ctx.node.properties['storage']['storage_size']
        vm_id = self.ctx.capabilities.get_all().values()[0][
            server_plugin.VSPHERE_SERVER_ID]

        storage_plugin.create()

        storage_file_name = \
            self.ctx.instance.runtime_properties[VSPHERE_STORAGE_FILE_NAME]
        self.logger.debug(
            "Check storage \'{0}\' is created".format(storage_file_name))
        storage = self.assert_storage_exists_and_get(vm_id, storage_file_name)
        self.logger.debug(
            "Check storage \'{0}\' settings".format(storage_file_name))
        self.assertEqual(storage_size * 1024**2, storage.capacityInKB)

        self.logger.debug("Delete storage \'{0}\'".format(storage_file_name))
        storage_plugin.delete()
        self.logger.debug(
            "Check storage \'{0}\' is deleted".format(storage_file_name))
        self.assert_no_storage(vm_id, storage_file_name)
Beispiel #11
0
    def test_storage_create(self, mock_client_get):
        mock_client_get().create_storage.side_effect = [(
            'file name',
            'something'
        )]

        # not provided capabilities
        self.mock_ctx.capabilities.get_all = Mock(return_value={})

        with self.assertRaises(NonRecoverableError):
            storage.create(
                storage={
                    'storage_size': 7,
                }, use_external_resource=False)

        # wrong list capabilities
        self.mock_ctx.capabilities.get_all = Mock(return_value={
            'vm_inst_id': {
                'name': 'Julie',
                'vsphere_server_id': '1',
            },
            'vm_inst_other': {
                'name': 'Julie',
                'vsphere_server_id': '2',
            },
        })

        with self.assertRaises(NonRecoverableError):
            storage.create(
                storage={
                    'storage_size': 7,
                }, use_external_resource=False)

        # correct settings
        self.mock_ctx.capabilities.get_all = Mock(return_value={
            'vm_inst_id': {
                'name': 'Julie',
                'vsphere_server_id': 'i',
            },
        })

        storage.create(
            storage={
                'storage_size': 7,
            }, use_external_resource=False)

        self.assertEqual(self.mock_ctx.instance.runtime_properties,
                         {'scsi_id': 'something',
                          'datastore_file_name': 'file name',
                          'attached_vm_id': 'i',
                          'attached_vm_name': 'Julie'})