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))
def setUp(self): action = Action('http://example.com/foo#', 'action') self.kind = Kind('http://example.com/foo#', 'bar', 'http://schemeas.ogf.org/occi/core#', [action], 'Some bla bla', {'foo': 'required', 'foo2': 'immutable', 'bar': ''}, '/foo/') mixin = Mixin('http://example.com/foo#', 'mixin') action = Action('http://example.com/foo#', 'action') self.target = Resource('/foo/target', self.kind, [], []) self.source = Resource('/foo/src', self.kind, [mixin], []) self.link = Link('/link/foo', self.kind, [], self.source, self.target) self.source.links = [self.link] self.source.actions = [action]
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])
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 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())
def test_type_system_for_sanity(self): ''' Test category, Action, Kind and Mixin. ''' cat1 = Category('http://example.com#', 'foo', '', {}, '') cat2 = Category('http://example.com#', 'foo', '', {}, '') kind = Kind('http://example.com#', 'bar') action = Action('http://example.com#', 'action') mixin = Mixin('http://example.com#', 'mixin') # test eq self.assertEquals(cat1, cat2) self.assertFalse(cat1 == str) self.assertFalse(cat1 == kind) # test str self.assertEqual(str(cat1), 'http://example.com#foo') # test repr self.assertEqual(repr(kind), 'kind') self.assertEqual(repr(action), 'action') self.assertEqual(repr(mixin), 'mixin')
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)
class TestParser(unittest.TestCase): ''' Test for the parser. ''' start_action = Action('http://schemas.ogf.org/occi/infrastructure#', 'start') compute = Kind('http://schemas.ogf.org/occi/infrastructure#', 'compute', title='A OCCI compute...', attributes={ 'occi.compute.cores': '', 'occi.compute.state': 'immutable', 'occi.compute.memory': 'required' }, related=[Resource.kind], actions=[start_action]) network_link = Kind('http://schemas.ogf.org/occi/infrastructure#', 'networkinterface', related=[Link.kind]) source = Resource('/1', compute, []) target = Resource('/2', compute, []) link1 = Link('/link/1', network_link, [], source, target) link2 = Link(None, network_link, [], source, target) registry = NonePersistentRegistry() def setUp(self): self.registry.add_resource(self.source.identifier, self.source) self.registry.add_resource(self.target.identifier, self.target) self.registry.set_backend(self.start_action, None) self.registry.set_backend(self.compute, None) self.registry.set_backend(self.network_link, None) self.link1.attributes = {'foo': 'bar'} def tearDown(self): for item in self.registry.get_categories(): self.registry.delete_mixin(item) #========================================================================== # Success #========================================================================== def test_get_category_for_success(self): ''' Tests if a mixin can be created. ''' # disabling 'Method could be func' pylint check (pyunit fault :-)) # pylint: disable=R0201 # mixin check... tmp = 'foo; scheme="http://example.com#"; location="/foo_bar/"' parser.get_category(tmp, self.registry.get_categories(), is_mixin=True) #========================================================================== # Failure #========================================================================== def test_get_category_for_failure(self): ''' Test with faulty category. ''' self.assertRaises(AttributeError, parser.get_category, 'some crap', self.registry.get_categories()) self.assertRaises(AttributeError, parser.get_category, 'foo; scheme="bar"', self.registry.get_categories()) # mixin with msg location check... tmp = 'foo; scheme="http://example.com#"' self.assertRaises(AttributeError, parser.get_category, tmp, self.registry.get_categories(), True) # mixin with faulty location check... tmp = 'foo; scheme="http://example.com#"; location="sdf"' self.assertRaises(AttributeError, parser.get_category, tmp, self.registry.get_categories(), True) def test_get_link_for_failure(self): ''' Test with msg category. ''' # no valid string... self.assertRaises(AttributeError, parser.get_link, 'some crap', None, self.registry.get_categories()) # no target... link_string = parser.get_link_str(self.link1) self.registry.delete_resource(self.target.identifier) self.assertRaises(AttributeError, parser.get_link, link_string, None, self.registry) def test_get_attributes_for_failure(self): ''' Verifies the parsing of attributes. ''' self.assertRaises(AttributeError, parser.get_attributes, 'bla blub') #========================================================================== # Sanity #========================================================================== def test_get_category_for_sanity(self): ''' Simple sanity check... ''' res = parser.get_category(parser.get_category_str(self.compute), self.registry.get_categories()) self.assertEqual(res, self.compute) def test_get_link_for_sanity(self): ''' Verifies that source and target are set... ''' link_string = parser.get_link_str(self.link1) link = parser.get_link(link_string, self.source, self.registry) self.assertEquals(link.kind, self.network_link) self.assertEquals(link.source, self.source) self.assertEquals(link.target, self.target) # 4 = 1 attr + core.id + core.src + core.target self.assertTrue(len(link.attributes) == 4) # identifier checks... link_string = parser.get_link_str(self.link1) link = parser.get_link(link_string, self.source, self.registry) self.assertEquals(link.identifier, '/link/1') tmp = link_string.split('; ') tmp.pop(2) link_string = '; '.join(tmp) link = parser.get_link(link_string, self.source, self.registry) self.assertEquals(link.identifier, None) def test_strip_all_for_sanity(self): ''' Tests if information get's stripped correctly. ''' self.assertEqual('bla', parser._strip_all('bla')) self.assertEqual('bla', parser._strip_all('"bla"')) self.assertEqual('bla', parser._strip_all(' bla ')) self.assertEqual('bla', parser._strip_all('"bla')) self.assertEqual('bla', parser._strip_all('bla" ')) self.assertEqual(' bla', parser._strip_all('" bla" ')) self.assertEqual('some text', parser._strip_all('"some text" ')) def test_get_attributes_for_sanity(self): ''' Verifies the parsing of attributes. ''' self.assertEquals(parser.get_attributes('foo=bar'), ('foo', 'bar')) self.assertEquals(parser.get_attributes('foo=bar '), ('foo', 'bar')) self.assertEquals(parser.get_attributes('foo= "some stuff"'), ('foo', 'some stuff')) self.assertEquals(parser.get_attributes('foo = "bar"'), ('foo', 'bar'))
# """ OCCI model extensions for OCCI SLA. """ from occi.core_model import Kind from occi.core_model import Link from occi.core_model import Mixin from occi.core_model import Action from occi.core_model import Resource # Agreement Definition # ************************************ ACCEPT_ACTION = Action(scheme="http://schemas.ogf.org/occi/sla#", term="accept", title="Accept an agreement offer") REJECT_ACTION = Action(scheme="http://schemas.ogf.org/occi/sla#", term="reject", title="Reject an agreement offer") SUSPEND_ACTION = Action(scheme="http://schemas.ogf.org/occi/sla#", term="suspend", title="Suspend suspend an agreement") UNSUSPEND_ACTION = Action(scheme="http://schemas.ogf.org/occi/sla#", term="unsuspend", title="Unsuspend a suspened agreement") AGREEMENT = Kind(
# ''' The OCCI Infrastructure extension. Created on Jul 20, 2011 @author: tmetsch ''' from occi.core_model import Action, Kind, Resource, Mixin, Link #============================================================================== # Compute #============================================================================== START = Action('http://schemas.ogf.org/occi/infrastructure/compute/action#', 'start', 'Start a compute resource') STOP = Action('http://schemas.ogf.org/occi/infrastructure/compute/action#', 'stop', 'Stop a compute resource', {'method': ''}) RESTART = Action('http://schemas.ogf.org/occi/infrastructure/compute/action#', 'restart', 'Restart a compute resource', {'method': ''}) SUSPEND = Action('http://schemas.ogf.org/occi/infrastructure/compute/action#', 'suspend', 'Suspend a compute resource', {'method': ''}) COMPUTE_ATTRIBUTES = { 'occi.compute.architecture': '', 'occi.compute.cores': '', 'occi.compute.hostname': '', 'occi.compute.speed': '',