Example #1
0
    def test_update_plugin(self, mock_parse_request, *args):
        params = {
            'storage_id': utils.generate_id('storage'),
            'name': 'storage-plugin-update',
            'plugin_info': {
                'plugin_id': utils.generate_id('storage'),
                'version': '3.0',
                'options': {},
            },
            'tags': {
                'update_key': 'update_value'
            },
            'domain_id': utils.generate_id('domain')
        }
        mock_parse_request.return_value = (params, {})
        storage_servicer = Storage()
        storage_info = storage_servicer.update_plugin(params, {})
        storage_data = MessageToDict(storage_info,
                                     preserving_proto_field_name=True)
        print_message(storage_info, 'test_update_storage_plugin')

        self.assertIsInstance(storage_info, storage_pb2.StorageInfo)
        self.assertEqual(storage_info.name, params['name'])
        self.assertDictEqual(storage_data['tags'], params['tags'])
        self.assertEqual(storage_info.plugin_info.version,
                         params['plugin_info']['version'])
        self.assertIsNotNone(storage_info.plugin_info)

        print(f'[TEST UPDATE STORAGE PLUGIN] {storage_data}')
Example #2
0
    def test_list_schedules(self, mock_parse_request, *args):
        mock_parse_request.return_value = ({}, {})

        storage_servicer = Storage()
        schedules_info = storage_servicer.list({}, {})

        print_message(schedules_info, 'test_list_schedules')

        self.assertIsInstance(schedules_info, storage_pb2.StoragesInfo)
        self.assertIsInstance(schedules_info.results[0],
                              storage_pb2.StorageInfo)
        self.assertEqual(schedules_info.total_count, 10)
Example #3
0
    def test_verify_plugin(self, mock_parse_request, *args):
        params = {
            'storage_id': utils.generate_id('storage'),
            'domain_id': utils.generate_id('domain')
        }
        mock_parse_request.return_value = (params, {})
        storage_servicer = Storage()
        storage_info = storage_servicer.verify_plugin(params, {})
        storage_data = MessageToDict(storage_info,
                                     preserving_proto_field_name=True)
        print_message(storage_info, 'test_deregister_storage_plugin')

        self.assertIsInstance(storage_info, Empty)

        print(f'[TEST VERIFY STORAGE PLUGIN] {storage_data}')
Example #4
0
    def test_get_storage(self, mock_parse_request, *args):
        mock_parse_request.return_value = ({}, {})
        params = {
            'domain_id': utils.generate_id('domain'),
            'storage_id': utils.generate_id('storage')
        }
        storage_servicer = Storage()
        storage_info = storage_servicer.get(params, {})
        storage_data = MessageToDict(storage_info,
                                     preserving_proto_field_name=True)

        print_message(storage_info, 'test_get_schedule')
        self.assertIsInstance(storage_info, storage_pb2.StorageInfo)

        print(f'[TEST GET STORAGE] {storage_data}')
Example #5
0
    def test_deregister_storage(self, mock_parse_request, *args):
        params = {
            'storage_id': utils.generate_id('storage'),
            'domain_id': utils.generate_id('domain')
        }
        mock_parse_request.return_value = (params, {})

        storage_servicer = Storage()
        storage_info = storage_servicer.deregister(params, {})
        storage_data = MessageToDict(storage_info,
                                     preserving_proto_field_name=True)

        print_message(storage_info, 'test_deregister_storage')
        # TODO : ASK!!
        # self.assertIsInstance(storage_info, Empty)
        # self.assertEqual(storage_info.state, storage_pb2.StorageInfo.State.DISABLED)

        print(f'[TEST DEREGISTER STORAGE] {storage_data}')
Example #6
0
    def test_disable_storage(self, mock_parse_request, *args):
        params = {
            'storage_id': utils.generate_id('storage'),
            'state': 'DISABLED',
            'domain_id': utils.generate_id('domain')
        }
        mock_parse_request.return_value = (params, {})

        storage_servicer = Storage()
        storage_info = storage_servicer.disable(params, {})
        storage_data = MessageToDict(storage_info,
                                     preserving_proto_field_name=True)

        print_message(storage_info, 'test_disable_storage')

        self.assertIsInstance(storage_info, storage_pb2.StorageInfo)
        self.assertEqual(storage_info.state,
                         storage_pb2.StorageInfo.State.DISABLED)

        print(f'[TEST DISABLE STORAGE] {storage_data}')
Example #7
0
    def test_register_storage(self, mock_parse_request, *args):
        params = {
            'name': utils.generate_id('storage', 4),
            'tags': {
                utils.random_string(5): utils.random_string(5)
            },
            'plugin_info': {
                'plugin_id': utils.generate_id('plugin'),
                'version': '1.1',
                'secret_id': utils.generate_id('secret')
            },
            'user_id': utils.generate_id('user'),
            'domain_id': utils.generate_id('domain')
        }
        mock_parse_request.return_value = (params, {})
        storage_servicer = Storage()

        storage_info = storage_servicer.register(params, {})
        print_message(storage_info, 'test_register_storage')

        storage_data = MessageToDict(storage_info,
                                     preserving_proto_field_name=True)

        self.assertIsInstance(storage_info, storage_pb2.StorageInfo)
        self.assertEqual(storage_info.name, params['name'])
        self.assertEqual(storage_data['state'], 'ENABLED')
        # self.assertIsNotNone(storage_info.capability)
        self.assertDictEqual(storage_data['tags'], params['tags'])
        self.assertIsInstance(
            storage_info.plugin_info,
            storage_pb2.PluginInfo)  # Check if 'PluginInfo' exists
        self.assertEqual(storage_data['plugin_info']['plugin_id'],
                         params['plugin_info']['plugin_id'])
        self.assertEqual(storage_data['plugin_info']['version'],
                         params['plugin_info']['version'])
        self.assertEqual(storage_data['domain_id'], params['domain_id'])
        self.assertIsNotNone(getattr(storage_info, 'created_at', None))

        print(f'[TEST REGISTER STORAGE] {storage_data}')
Example #8
0
    def test_update_storage(self, mock_parse_request, *args):
        params = {
            'storage_id': utils.generate_id('storage'),
            'name': 'update-storage-name',
            'tags': {
                'update_key': 'update_value'
            },
            'domain_id': utils.generate_id('domain')
        }
        mock_parse_request.return_value = (params, {})

        storage_servicer = Storage()
        storage_info = storage_servicer.update(params, {})

        print_message(storage_info, 'test_update_schedule')
        storage_data = MessageToDict(storage_info,
                                     preserving_proto_field_name=True)

        self.assertIsInstance(storage_info, storage_pb2.StorageInfo)
        self.assertEqual(storage_data['name'], params['name'])
        self.assertEqual(storage_data['storage_id'], params['storage_id'])
        self.assertDictEqual(storage_data['tags'], params['tags'])

        print(f'[TEST UPDATE STORAGE] {storage_data}')