def test_show_resource(self, mock_image_get):
     image_info = namedtuple('image_info', field_names=['id', 'name'])
     plugin = ImageProtectablePlugin(self._context)
     mock_image_get.return_value = \
         image_info(id='123', name='name123')
     self.assertEqual(plugin.show_resource(self._context, '123'),
                      resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                                        id='123', name='name123'))
 def test_show_resource(self):
     image_info = namedtuple('image_info', field_names=['id', 'name'])
     plugin = ImageProtectablePlugin(self._context)
     plugin._glance_client.images.get = \
         mock.MagicMock(return_value=image_info(id='123', name='name123'))
     self.assertEqual(plugin.show_resource('123'),
                      resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                                        id='123', name='name123'))
 def test_get_server_dependent_resources(self):
     vm = server_info(id='server1',
                      type=constants.SERVER_RESOURCE_TYPE,
                      image=dict(id='123'))
     plugin = ImageProtectablePlugin(self._context)
     plugin._nova_client.servers.get = mock.MagicMock(return_value=vm)
     self.assertEqual(plugin.get_dependent_resources(vm),
                      [resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                                         id='123')])
 def test_get_server_dependent_resources(self, mock_server_get):
     vm = server_info(id='server1',
                      type=constants.SERVER_RESOURCE_TYPE,
                      name='nameserver1',
                      image=dict(id='123', name='name123'))
     plugin = ImageProtectablePlugin(self._context)
     mock_server_get.return_value = vm
     self.assertEqual(plugin.get_dependent_resources(self._context, vm),
                      [resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                                         id='123', name='name123')])
 def test_show_resource(self, mock_image_get):
     image_info = namedtuple('image_info', field_names=['id', 'name'])
     plugin = ImageProtectablePlugin(self._context)
     mock_image_get.return_value = \
         image_info(id='123', name='name123')
     self.assertEqual(
         plugin.show_resource(self._context, '123'),
         resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                           id='123',
                           name='name123'))
 def test_get_project_dependent_resources(self):
     project = project_info(id='abcd', type=constants.PROJECT_RESOURCE_TYPE)
     plugin = ImageProtectablePlugin(self._context)
     plugin._glance_client.images.list = mock.MagicMock(return_value=[
         image_info('123', 'abcd'),
         image_info('456', 'efgh'),
     ])
     self.assertEqual(plugin.get_dependent_resources(project),
                      [resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                                         id='123')])
 def test_get_server_dependent_resources(self, mock_server_get):
     vm = server_info(id='server1',
                      type=constants.SERVER_RESOURCE_TYPE,
                      name='nameserver1',
                      image=dict(id='123', name='name123'))
     plugin = ImageProtectablePlugin(self._context)
     mock_server_get.return_value = vm
     self.assertEqual(plugin.get_dependent_resources(self._context, vm), [
         resource.Resource(
             type=constants.IMAGE_RESOURCE_TYPE, id='123', name='name123')
     ])
 def test_create_client_by_catalog(self):
     CONF.set_default('glance_catalog_info', 'image:glance:publicURL',
                      'glance_client')
     CONF.set_default('nova_catalog_info', 'compute:nova:publicURL',
                      'nova_client')
     plugin = ImageProtectablePlugin(self._context)
     self.assertEqual(
         plugin._glance_client(self._context).http_client.endpoint,
         'http://127.0.0.1:9292')
     self.assertEqual(
         plugin._nova_client(self._context).client.management_url,
         'http://127.0.0.1:8774/v2.1/abcd')
 def test_create_client_by_endpoint(self):
     CONF.set_default('glance_endpoint', 'http://127.0.0.1:9292',
                      'glance_client')
     CONF.set_default('nova_endpoint', 'http://127.0.0.1:8774/v2.1',
                      'nova_client')
     plugin = ImageProtectablePlugin(self._context)
     self.assertEqual(
         plugin._glance_client(self._context).http_client.endpoint,
         'http://127.0.0.1:9292')
     self.assertEqual(
         plugin._nova_client(self._context).client.management_url,
         'http://127.0.0.1:8774/v2.1/abcd')
 def test_list_resources(self):
     plugin = ImageProtectablePlugin(self._context)
     plugin._glance_client.images.list = mock.MagicMock(return_value=[
         image_info(id='123', name='name123', owner='abcd'),
         image_info(id='456', name='name456', owner='efgh'),
     ])
     self.assertEqual(plugin.list_resources(),
                      [resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                                         id='123', name='name123'),
                       resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                                         id='456', name='name456')
                       ])
 def test_create_client_by_endpoint(self):
     CONF.set_default('glance_endpoint', 'http://127.0.0.1:9292',
                      'glance_client')
     CONF.set_default('nova_endpoint', 'http://127.0.0.1:8774/v2.1',
                      'nova_client')
     plugin = ImageProtectablePlugin(self._context)
     self.assertEqual(
         plugin._glance_client(self._context).http_client.endpoint,
         'http://127.0.0.1:9292')
     self.assertEqual(
         plugin._nova_client(self._context).client.management_url,
         'http://127.0.0.1:8774/v2.1/abcd')
 def test_create_client_by_catalog(self):
     CONF.set_default('glance_catalog_info', 'image:glance:publicURL',
                      'glance_client')
     CONF.set_default('nova_catalog_info', 'compute:nova:publicURL',
                      'nova_client')
     plugin = ImageProtectablePlugin(self._context)
     self.assertEqual(
         plugin._glance_client(self._context).http_client.endpoint,
         'http://127.0.0.1:9292')
     self.assertEqual(
         plugin._nova_client(self._context).client.management_url,
         'http://127.0.0.1:8774/v2.1/abcd')
 def test_list_resources(self, mokc_image_list):
     plugin = ImageProtectablePlugin(self._context)
     mokc_image_list.return_value = \
         [
             image_info(id='123', name='name123', owner='abcd'),
             image_info(id='456', name='name456', owner='efgh'),
         ]
     self.assertEqual(plugin.list_resources(self._context),
                      [resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                                         id='123', name='name123'),
                       resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                                         id='456', name='name456')
                       ])
 def test_list_resources(self, mokc_image_list):
     plugin = ImageProtectablePlugin(self._context)
     mokc_image_list.return_value = \
         [
             image_info(id='123', name='name123', owner='abcd'),
             image_info(id='456', name='name456', owner='efgh'),
         ]
     self.assertEqual(plugin.list_resources(self._context), [
         resource.Resource(
             type=constants.IMAGE_RESOURCE_TYPE, id='123', name='name123'),
         resource.Resource(
             type=constants.IMAGE_RESOURCE_TYPE, id='456', name='name456')
     ])
 def test_get_project_dependent_resources(self, mock_image_list):
     project = project_info(id='abcd', type=constants.PROJECT_RESOURCE_TYPE,
                            name='nameabcd')
     plugin = ImageProtectablePlugin(self._context)
     mock_image_list.return_value = \
         [
             image_info('123', 'abcd', 'nameabcd'),
             image_info('456', 'efgh', 'nameefgh'),
         ]
     self.assertEqual(
         plugin.get_dependent_resources(self._context, project),
         [resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                            name='nameabcd',
                            id='123')])
 def test_get_project_dependent_resources(self, mock_image_list):
     project = project_info(id='abcd',
                            type=constants.PROJECT_RESOURCE_TYPE,
                            name='nameabcd')
     plugin = ImageProtectablePlugin(self._context)
     mock_image_list.return_value = \
         [
             image_info('123', 'abcd', 'nameabcd'),
             image_info('456', 'efgh', 'nameefgh'),
         ]
     self.assertEqual(
         plugin.get_dependent_resources(self._context, project), [
             resource.Resource(type=constants.IMAGE_RESOURCE_TYPE,
                               name='nameabcd',
                               id='123')
         ])
 def test_get_parent_resource_type(self):
     plugin = ImageProtectablePlugin(self._context)
     self.assertItemsEqual(
         plugin.get_parent_resource_types(),
         (constants.SERVER_RESOURCE_TYPE, constants.PROJECT_RESOURCE_TYPE))
 def test_get_resource_type(self):
     plugin = ImageProtectablePlugin(self._context)
     self.assertEqual(
         plugin.get_resource_type(),
         constants.IMAGE_RESOURCE_TYPE)
 def test_get_resource_type(self):
     plugin = ImageProtectablePlugin(self._context)
     self.assertEqual(plugin.get_resource_type(),
                      constants.IMAGE_RESOURCE_TYPE)
 def test_get_parent_resource_type(self):
     plugin = ImageProtectablePlugin(self._context)
     self.assertItemsEqual(
         plugin.get_parent_resource_types(),
         (constants.SERVER_RESOURCE_TYPE, constants.PROJECT_RESOURCE_TYPE))