示例#1
0
    def setUp(self):
        self.kind1 = Kind('http://www.example.com#', 'foo')
        self.kind2 = Kind('http://www.example.com#', 'bar')
        self.mixin = Mixin('http://www.example.com#', 'mixin')

        self.registry.set_backend(self.kind1, KindBackend())
        self.registry.set_backend(self.kind2, KindBackend())
示例#2
0
class TestKindBackend(unittest.TestCase):
    '''
    Some sanity checks for convenient routines in the backend.
    '''

    def setUp(self):
        self.back = KindBackend()
        self.action = Action('foo', 'action')
        self.kind = Kind('foo', 'bar', actions=[self.action],
                         attributes={'foo': 'mutable', 'bar': 'required'})
        self.link_kind = Kind('foo', 'bar', related=self.kind)
        self.resource = Resource('/foo/1', self.kind, [])
        self.resource.actions = [self.action]
        self.link = Link('/link/1', self.link_kind, [], None, self.resource)

    def test_simple_calls(self):
        '''
        Test all possible calls if the pass...
        '''
        self.back.create(None)
        self.back.retrieve(None)
        self.back.delete(None)
        self.back.update(None, None)
        self.back.replace(None, None)

    def test_is_related_for_sanity(self):
        '''
        Tests links...
        '''
        self.assertTrue(backend.is_related_valid(self.link))
        link2 = Link('/link/2', self.kind, [], None, self.resource)
        self.assertFalse(backend.is_related_valid(link2))

    def test_attr_mutable_for_sanity(self):
        '''
        Test attributes.
        '''
        self.assertFalse(backend.is_attr_mutable(self.kind, 'bar'))
        self.assertTrue(backend.is_attr_mutable(self.kind, 'foo'))

    def test_attr_required_for_sanity(self):
        '''
        Test attributes.
        '''
        self.assertFalse(backend.is_attr_required(self.kind, 'foo'))
        self.assertTrue(backend.is_attr_required(self.kind, 'bar'))

    def test_action_applicable_for_sanity(self):
        '''
        Test action stuff.
        '''
        self.assertTrue(backend.is_action_applicable(self.resource,
                                                     self.action))

        action2 = Action('foo', 'start')
        self.assertFalse(backend.is_action_applicable(self.resource, action2))

        action3 = Action('foo', 'start')
        self.resource.actions.append(action3)
        self.assertFalse(backend.is_action_applicable(self.resource, action3))
示例#3
0
    def setUp(self):
        self.app = Application([(r"(.*)", ResourceWrapper)])
        self.registry.set_renderer('text/occi',
                                   TextOcciRendering(self.registry))

        self.registry.set_backend(COMPUTE, SimpleComputeBackend())
        self.registry.set_backend(NETWORK, KindBackend())
        self.registry.set_backend(NETWORKINTERFACE, KindBackend())
        self.registry.set_backend(START, SimpleComputeBackend())
示例#4
0
 def setUp(self):
     self.back = KindBackend()
     self.action = Action('foo', 'action')
     self.kind = Kind('foo',
                      'bar',
                      actions=[self.action],
                      attributes={
                          'foo': 'mutable',
                          'bar': 'required'
                      })
     self.link_kind = Kind('foo', 'bar', related=self.kind)
     self.resource = Resource('/foo/1', self.kind, [])
     self.resource.actions = [self.action]
     self.link = Link('/link/1', self.link_kind, [], None, self.resource)
示例#5
0
    def setUp(self):
        self.test_kind = Kind('http://example.com#', 'test')
        self.link_kind = Kind('http://example.com#link', 'link')
        mixins = []
        self.action = Action('http://example.com#', 'action')
        self.src_entity = Resource(None, self.test_kind, mixins, [])
        self.trg_entity = Resource('/foo/trg', self.test_kind, mixins, [])
        self.link1 = Link('/link/1', self.link_kind, [], self.src_entity,
                          self.trg_entity)
        self.src_entity.links = [self.link1]

        self.registry.add_resource(self.trg_entity.identifier, self.trg_entity)
        self.registry.set_backend(self.test_kind, KindBackend())
        self.registry.set_backend(self.link_kind, KindBackend())
        self.registry.set_backend(self.action, ActionBackend())
示例#6
0
    def __init__(self):
        try:
            # added try as many sm.cfg still have no mongo section
            mongo_addr = CONFIG.get('mongo', 'host', None)
        except NoSectionError:
            mongo_addr = None

        sm_name = os.environ.get('SM_NAME', 'SAMPLE_SM')
        mongo_service_name = sm_name.upper().replace('-', '_')

        db_host_key = mongo_service_name + '_MONGO_SERVICE_HOST'
        db_port_key = mongo_service_name + '_MONGO_SERVICE_PORT'
        db_host = os.environ.get(db_host_key, False)
        db_port = os.environ.get(db_port_key, False)
        db_user = os.environ.get('DB_USER', False)
        db_password = os.environ.get('DB_PASSWORD', False)

        if db_host and db_port and db_user and db_password:
            mongo_addr = 'mongodb://%s:%s@%s:%s' % (db_user, db_password,
                                                    db_host, db_port)

        if mongo_addr is None:
            reg = SMRegistry()
        else:
            reg = SMMongoRegistry(mongo_addr)
        super(MApplication, self).__init__(reg)

        self.register_backend(Link.kind, KindBackend())
示例#7
0
    def setUp(self):
        self.registry.set_hostname('http://127.0.0.1')
        self.app = Application([(r"(.*)/", CollectionWrapper)])

        self.registry.set_renderer('text/plain',
                                   TextPlainRendering(self.registry))
        self.registry.set_renderer('text/occi',
                                   TextOcciRendering(self.registry))
        self.registry.set_renderer('text/uri-list',
                                   TextUriListRendering(self.registry))

        self.mixin = Mixin('foo', 'mystuff')

        self.compute = Resource('/compute/1', COMPUTE, [])
        self.compute.attributes = {'foo2': 'bar2'}
        self.network = Resource('/network/1', NETWORK, [IPNETWORK])
        self.network_interface = Link('/network/interface/1', NETWORKINTERFACE,
                                      [IPNETWORKINTERFACE], self.compute,
                                      self.network)

        self.registry.set_backend(COMPUTE, SimpleComputeBackend())
        self.registry.set_backend(NETWORK, KindBackend())
        self.registry.set_backend(self.mixin, MixinBackend())
        self.registry.set_backend(START, SimpleComputeBackend())

        self.registry.add_resource(self.compute.identifier, self.compute)
        self.registry.add_resource(self.network.identifier, self.network)
        self.registry.add_resource(self.network_interface.identifier,
                                   self.network_interface)
示例#8
0
    def setUp(self):
        self.app = Application([(r"(.*)", ResourceWrapper)])
        self.registry.set_renderer('text/plain',
                                   TextPlainRendering(self.registry))
        self.registry.set_renderer('text/occi',
                                   TextOcciRendering(self.registry))

        self.registry.set_backend(COMPUTE, SimpleComputeBackend())
        self.registry.set_backend(NETWORK, KindBackend())
        self.registry.set_backend(NETWORKINTERFACE, KindBackend())
        self.registry.set_backend(START, SimpleComputeBackend())

        self.compute = Resource('/compute/1', COMPUTE, [])
        self.network = Resource('/network/1', NETWORK, [IPNETWORK])

        self.registry.add_resource('/compute/1', self.compute)
        self.registry.add_resource('/network/1', self.network)
示例#9
0
 def setUp(self):
     self.back = KindBackend()
     self.action = Action('foo', 'action')
     self.kind = Kind('foo', 'bar', actions=[self.action],
                      attributes={'foo': 'mutable', 'bar': 'required'})
     self.link_kind = Kind('foo', 'bar', related=self.kind)
     self.resource = Resource('/foo/1', self.kind, [])
     self.resource.actions = [self.action]
     self.link = Link('/link/1', self.link_kind, [], None, self.resource)
示例#10
0
    def setUp(self):
        self.app = Application([(r"/-/", QueryWrapper)])
        self.registry.set_renderer('text/occi',
                                   TextOcciRendering(self.registry))

        backend = KindBackend()

        self.registry.set_backend(COMPUTE, backend)
        self.registry.set_backend(STORAGE, backend)
        self.registry.set_backend(NETWORK, backend)
示例#11
0
    def setUp(self):
        self.kind1 = Kind('http://example.com#', '1')
        self.kind2 = Kind('http://example.com#', '2')
        self.action = Action('http://example.com#', 'action')
        self.mixin = Mixin('http://example.com#', 'mixin')

        self.registry.set_backend(self.kind1, KindBackend())
        self.registry.set_backend(self.kind2, DummyBackend())
        self.registry.set_backend(self.action, ActionBackend())
        self.registry.set_backend(self.mixin, MixinBackend())

        self.entity = Resource('foo', self.kind1, [self.kind2])
示例#12
0
文件: service.py 项目: sufuf3/icnaas
    def __init__(self):
        try:
            # added try as many sm.cfg still have no mongo section
            mongo_addr = CONFIG.get('mongo', 'host', None)
        except NoSectionError:
            mongo_addr = None

        if mongo_addr is None:
            reg = SMRegistry()
        else:
            reg = SMMongoRegistry(mongo_addr)
        super(MApplication, self).__init__(reg)

        self.register_backend(Link.kind, KindBackend())
示例#13
0
    def test_register_backend_for_sanity(self):
        '''
        Test registration.
        '''
        back = KindBackend()
        back1 = MixinBackend()
        back2 = ActionBackend()
        self.service.register_backend(COMPUTE, back)
        self.service.register_backend(IPNETWORKINTERFACE, back1)
        self.service.register_backend(START, back2)

        self.assertTrue(self.registry.get_backend(COMPUTE) == back)
        self.assertTrue(self.registry.get_backend(IPNETWORKINTERFACE) == back1)
        self.assertTrue(self.registry.get_backend(START) == back2)
示例#14
0
    def setUp(self):
        self.rendering = TextOcciRendering(self.registry)
        # type system...
        self.kind = Kind('http://example.com#', 'foo', related=[Resource.kind])
        self.invalid_kind = Kind('http://example.com#', 'invalid')
        self.link = Kind('http://example.com#', 'link', related=[Link.kind])
        self.mixin = Mixin('http://example.com#', 'mixin')
        self.action = Action('http://example.com#', 'action')

        self.registry.set_backend(self.kind, KindBackend())
        self.registry.set_backend(self.invalid_kind, KindBackend())
        self.registry.set_backend(self.link, KindBackend())
        self.registry.set_backend(self.mixin, MixinBackend())
        self.registry.set_backend(self.action, ActionBackend())

        # 2 linked entities
        self.entity = Resource('/foo/1', self.kind, [self.mixin])
        trg = Resource('/foo/2', self.kind, [], [])
        self.link1 = Link('/link/1', self.link, [], self.entity, trg)
        self.entity.links = [self.link1]

        self.registry.add_resource('/foo/2', trg)
        self.registry.add_resource('/link/1', self.link1)
        self.registry.add_resource('/foo/1', self.entity)
示例#15
0
    def setUp(self):
        self.kind = Kind('http://example.com/foo#', 'bar')
        self.link_kind = Kind('http://example.com/foo#', 'link')
        self.mixin = Mixin('http://example.com/foo#', 'mixin')

        target = Resource('/foo/target', self.kind, [], [])

        source = Resource('/foo/src', self.kind, [self.mixin], [])
        source.attributes = {'foo': 'bar'}

        link = Link('/link/foo', self.link_kind, [], source, target)
        link.attributes = {'foo': 'bar'}
        source.links = [link]

        self.resources = [source, target, link]
        for item in self.resources:
            self.registry.add_resource(item.identifier, item)

        self.registry.set_backend(self.kind, KindBackend())
        self.registry.set_backend(self.mixin, MixinBackend())
示例#16
0
 def __init__(self):
     super(MApplication, self).__init__(registry=SMRegistry())
     self.register_backend(Link.kind, KindBackend())
示例#17
0
class TestKindBackend(unittest.TestCase):
    '''
    Some sanity checks for convenient routines in the backend.
    '''
    def setUp(self):
        self.back = KindBackend()
        self.action = Action('foo', 'action')
        self.kind = Kind('foo',
                         'bar',
                         actions=[self.action],
                         attributes={
                             'foo': 'mutable',
                             'bar': 'required'
                         })
        self.link_kind = Kind('foo', 'bar', related=self.kind)
        self.resource = Resource('/foo/1', self.kind, [])
        self.resource.actions = [self.action]
        self.link = Link('/link/1', self.link_kind, [], None, self.resource)

    def test_simple_calls(self):
        '''
        Test all possible calls if the pass...
        '''
        self.back.create(None)
        self.back.retrieve(None)
        self.back.delete(None)
        self.back.update(None, None)
        self.back.replace(None, None)

    def test_is_related_for_sanity(self):
        '''
        Tests links...
        '''
        self.assertTrue(backend.is_related_valid(self.link))
        link2 = Link('/link/2', self.kind, [], None, self.resource)
        self.assertFalse(backend.is_related_valid(link2))

    def test_attr_mutable_for_sanity(self):
        '''
        Test attributes.
        '''
        self.assertFalse(backend.is_attr_mutable(self.kind, 'bar'))
        self.assertTrue(backend.is_attr_mutable(self.kind, 'foo'))

    def test_attr_required_for_sanity(self):
        '''
        Test attributes.
        '''
        self.assertFalse(backend.is_attr_required(self.kind, 'foo'))
        self.assertTrue(backend.is_attr_required(self.kind, 'bar'))

    def test_action_applicable_for_sanity(self):
        '''
        Test action stuff.
        '''
        self.assertTrue(
            backend.is_action_applicable(self.resource, self.action))

        action2 = Action('foo', 'start')
        self.assertFalse(backend.is_action_applicable(self.resource, action2))

        action3 = Action('foo', 'start')
        self.resource.actions.append(action3)
        self.assertFalse(backend.is_action_applicable(self.resource, action3))
示例#18
0
    def setUp(self):
        self.kind1 = Kind('http://example.com#', '1')
        self.kind2 = Kind('http://example.com#', '2', location='/foo/')

        self.registry.set_backend(self.kind1, KindBackend())
        self.registry.set_backend(self.kind2, DummyBackend())