def test_create_image_extra_prop_invalid_role(self):
     self.context = glance.context.RequestContext(tenant=TENANT1,
                                                  roles=['imaginary-role'])
     self.image_factory = property_protections.ProtectedImageFactoryProxy(
         self.factory, self.context, self.property_rules)
     extra_props = {'foo': 'bar', 'spl_create_prop': 'c'}
     self.assertRaises(exception.ReservedProperty,
                       self.image_factory.new_image,
                       extra_properties=extra_props)
 def test_create_image_extra_prop_admin(self):
     self.context = glance.context.RequestContext(tenant=TENANT1,
                                                  roles=['admin'])
     self.image_factory = property_protections.ProtectedImageFactoryProxy(
         self.factory, self.context, self.property_rules)
     extra_props = {'foo': 'bar', 'spl_create_prop': 'c'}
     image = self.image_factory.new_image(extra_properties=extra_props)
     expected_extra_props = {'foo': 'bar', 'spl_create_prop': 'c'}
     self.assertEqual(image.extra_properties, expected_extra_props)
 def test_create_image_no_extra_prop(self):
     self.context = glance.context.RequestContext(tenant=TENANT1,
                                                  roles=['spl_role'])
     self.image_factory = property_protections.ProtectedImageFactoryProxy(
         self.factory, self.context, self.property_rules)
     extra_props = {}
     image = self.image_factory.new_image(extra_properties=extra_props)
     expected_extra_props = {}
     self.assertEqual(image.extra_properties, expected_extra_props)
 def test_create_image_extra_prop_reserved_property(self):
     self.context = glance.context.RequestContext(tenant=TENANT1,
                                                  roles=['spl_role'])
     self.image_factory = property_protections.ProtectedImageFactoryProxy(
         self.factory, self.context, self.property_rules)
     extra_props = {'foo': 'bar', 'spl_create_prop': 'c'}
     # no reg ex for property 'foo' is mentioned for spl_role in config
     self.assertRaises(exception.ReservedProperty,
                       self.image_factory.new_image,
                       extra_properties=extra_props)
Beispiel #5
0
 def get_image_factory(self, context, authorization_layer=True):
     factory = glance.domain.ImageFactory()
     factory = glance.location.ImageFactoryProxy(factory, context,
                                                 self.store_api,
                                                 self.store_utils)
     factory = glance.quota.ImageFactoryProxy(factory, context, self.db_api,
                                              self.store_utils)
     if authorization_layer:
         factory = policy.ImageFactoryProxy(factory, context, self.policy)
     factory = glance.notifier.ImageFactoryProxy(factory, context,
                                                 self.notifier)
     if property_utils.is_property_protection_enabled():
         property_rules = property_utils.PropertyRules(self.policy)
         factory = property_protections.ProtectedImageFactoryProxy(
             factory, context, property_rules)
     if authorization_layer:
         factory = authorization.ImageFactoryProxy(factory, context)
     return factory
Beispiel #6
0
 def get_image_factory(self, context):
     image_factory = glance.domain.ImageFactory()
     store_image_factory = glance.location.ImageFactoryProxy(
         image_factory, context, self.store_api, self.store_utils)
     quota_image_factory = glance.quota.ImageFactoryProxy(
         store_image_factory, context, self.db_api, self.store_utils)
     policy_image_factory = policy.ImageFactoryProxy(
         quota_image_factory, context, self.policy)
     notifier_image_factory = glance.notifier.ImageFactoryProxy(
         policy_image_factory, context, self.notifier)
     if property_utils.is_property_protection_enabled():
         property_rules = property_utils.PropertyRules(self.policy)
         pif = property_protections.ProtectedImageFactoryProxy(
             notifier_image_factory, context, property_rules)
         authorized_image_factory = authorization.ImageFactoryProxy(
             pif, context)
     else:
         authorized_image_factory = authorization.ImageFactoryProxy(
             notifier_image_factory, context)
     return authorized_image_factory