def get_instance(self, id=None, name=None): if id: # submodules instances are invisible for lists return Instance(id=id, organization=self.organization).init_router( self._router) return Instance.get(self._router, self.organization, name, application=self)
def get_instance(self, id=None, name=None): """ Get instance object by name or id. If application set, search within the application. """ log.info("Picking instance: %s (%s)" % (name, id)) if id: # submodule instances are invisible for lists return Instance(id=id, organization=self).init_router(self._router) return Instance.get(self._router, self, name)
def clean(self, timeout=3): log.info("cleaning sandbox...") for instanceData in self.sandbox['instances']: instance = Instance(context=self.platform.context, id=instanceData["id"]) instance.destroy() if not instance.destroyed(timeout): log.error( "Instance was not destroyed properly {0}: {1}".format(instanceData["id"], instanceData["name"]) ) log.info("sandbox cleaned")
def clean(self, timeout=3): log.info("cleaning sandbox...") for instanceData in self.sandbox['instances']: instance = Instance(context=self.platform.context, id=instanceData["id"]) instance.destroy() if not instance.destroyed(timeout): log.error( "Instance was not destroyed properly {0}: {1}".format( instanceData["id"], instanceData["name"])) log.info("sandbox cleaned")
def create_instance(self, application, revision=None, environment=None, name=None, parameters=None, submodules=None, destroyInterval=None): """ Launches instance in application and returns Instance object. """ from qubell.api.private.instance import Instance return Instance.new(self._router, application, revision, environment, name, parameters, submodules, destroyInterval)
def test_launch_basic_non_shared_3level_hierapp(self): """ Launch hierarchical app with childs as not shared instance. Check that launching parent launches all childs instance. """ parent_instance = self.parent.launch(destroyInterval=300000) self.assertTrue( parent_instance, "%s-%s: Parent instance failed to launch" % (self.prefix, self._testMethodName)) self.assertTrue( parent_instance.ready(), "%s-%s: Parent instance not in 'running' state after timeout" % (self.prefix, self._testMethodName)) self.assertTrue( parent_instance.submodules) # Check we have submodules started self.assertEqual(parent_instance.submodules[0]['status'], 'Running') middle_instance = Instance( self.context, id=parent_instance.submodules[0]['id'] ) # initialize middle instance (we can only get id from parent) self.assertTrue(middle_instance.submodules ) # Check middle instance start it's dependency self.assertEqual(middle_instance.submodules[0]['status'], 'Running') self.assertTrue( parent_instance.delete(), "%s-%s: Parent instance failed to destroy" % (self.prefix, self._testMethodName)) self.assertTrue( parent_instance.destroyed(), "%s-%s: Parent instance not in 'destroyed' state after timeout" % (self.prefix, self._testMethodName)) self.assertFalse( middle_instance.status) # Check submodule does not exists
def test_switch_last_child_shared_standalone_and_back(self): """ Launch hierarchical app with non shared instance. Change last child to shared, check. Switch back. """ # Run parent with NON shared child parent_instance = self.parent.launch(destroyInterval=3000000) self.assertTrue(parent_instance, "%s-%s: Parent instance failed to launch" % (self.prefix, self._testMethodName)) self.assertTrue(parent_instance.ready(),"%s-%s: Parent instance not in 'running' state after timeout" % (self.prefix, self._testMethodName)) non_shared_rev = self.parent.create_revision(name='non-shared-child', instance=parent_instance) middle_instance = Instance(self.context, id=parent_instance.submodules[0]['id']) # initialize middle instance (we can only get id from parent) # Ensure we use non shared instance self.assertEqual(middle_instance.submodules[0]['status'], 'Running') self.assertNotEqual(middle_instance.submodules[0]['id'], self.last_child_instance.instanceId) # Reconfigure parent to use shared child parameters = { 'top_parent_in.last_child_input': 'UPD by test', 'top_parent_in.middle_child_input': 'UPD by test'} submodules = { 'middle_child': { 'parameters': { 'last_child_in.app_input': 'UPD by test', 'middle_child_in.app_input': 'UPD by test'}, 'submodules':{ 'last_child': { 'revisionId': self.last_child_rev.revisionId }}}} self.assertTrue(parent_instance.reconfigure(parameters=parameters, submodules=submodules)) # Check parent instance is ok self.assertTrue(parent_instance.ready(), "Instance failed to reconfigure") self.assertTrue(parent_instance.submodules, 'No submodules found') self.assertEqual(parent_instance.submodules[0]['status'], 'Running') self.assertEqual(parent_instance.submodules[0]['id'], middle_instance.instanceId) # Check last child is shared self.assertEqual(middle_instance.submodules[0]['status'], 'Running') self.assertEqual(middle_instance.submodules[0]['id'], self.last_child_instance.instanceId) # Switch back to non shared instance self.assertTrue(parent_instance.reconfigure(revisionId=non_shared_rev.revisionId)) # Check parent is ok self.assertTrue(parent_instance.ready(), "Instance failed to reconfigure") self.assertEqual(parent_instance.submodules[0]['status'], 'Running') # Check we use non-shared last child again last_instance = Instance(self.context, id=middle_instance.submodules[0]['id']) self.assertTrue(last_instance.ready()) self.assertEqual(middle_instance.submodules[0]['status'], 'Running') self.assertNotEqual(middle_instance.submodules[0]['id'], self.last_child_instance.instanceId) self.assertTrue(parent_instance.delete(), "%s-%s: Parent instance failed to destroy" % (self.prefix, self._testMethodName)) self.assertTrue(parent_instance.destroyed(), "%s-%s: Parent instance not in 'destroyed' state after timeout" % (self.prefix, self._testMethodName))
def get_instance(self, id=None, name=None): if id: # submodules instances are invisible for lists return Instance(id=id, organization=self.organization).init_router(self._router) return Instance.get(self._router, self.organization, name, application=self)
def test_launch_3level_hierapp_shared_middle_shared_last_child(self): """ Launch 3-level hierarchical app with middle child as shared instance and last child shared too. We create basic hierapp, set it as shared and then use it in another hierapp :) """ # Create shared last child last_child_instance = self.last_child.launch(destroyInterval=600000) self.assertTrue(last_child_instance) self.assertTrue(last_child_instance.ready()) last_child_revision = self.last_child.create_revision( name='%s-shared_last_child' % self._testMethodName, instance=last_child_instance) self.shared_service.add_shared_instance(last_child_revision, last_child_instance) # Create shared middle child parameters = { 'last_child_in.app_input': 'Parent in to Last child', 'middle_child_in.app_input': 'Middle param' } submodules = { 'last_child': { 'revisionId': last_child_revision.revisionId } } middle_child_instance = self.middle_child.launch( destroyInterval=600000, parameters=parameters, submodules=submodules) self.assertTrue(middle_child_instance) self.assertTrue(middle_child_instance.ready()) # Check we have last as shared self.assertEqual(last_child_instance.instanceId, middle_child_instance.submodules[0]['id']) middle_child_revision = self.middle_child.create_revision( name='%s-shared_middle_child' % self._testMethodName, instance=middle_child_instance) self.shared_service.add_shared_instance(middle_child_revision, middle_child_instance) # Start parent parameters = { 'top_parent_in.last_child_input': 'Hello from TOP parent to last child', 'top_parent_in.middle_child_input': 'Hello from TOP parent to middle child' } submodules = { 'middle_child': { 'revisionId': middle_child_revision.revisionId } } parent_instance = self.parent.launch(destroyInterval=600000, parameters=parameters, submodules=submodules) self.assertTrue( parent_instance, "%s-%s: Parent instance failed to launch" % (self.prefix, self._testMethodName)) self.assertTrue( parent_instance.ready(), "%s-%s: Parent instance not in 'running' state after timeout" % (self.prefix, self._testMethodName)) # Check we have submodules started self.assertTrue(parent_instance.submodules) self.assertEqual(parent_instance.submodules[0]['status'], 'Running') # Check middle child is shared self.assertEqual(parent_instance.submodules[0]['id'], middle_child_instance.instanceId, "Middle child used is not shared one") mid = Instance(self.context, id=parent_instance.submodules[0]['id']) self.assertEqual(middle_child_instance.status, 'Running') # Check shared still alive # Check last child is shared self.assertEqual(mid.submodules[0]['id'], last_child_instance.instanceId, "Last child used is not shared one" ) # Check we use shared last instance # Cleaning self.assertTrue( parent_instance.delete(), "%s-%s: Parent instance failed to destroy" % (self.prefix, self._testMethodName)) self.assertTrue( parent_instance.destroyed(), "%s-%s: Parent instance not in 'destroyed' state after timeout" % (self.prefix, self._testMethodName)) # Remove created services and middle instance self.shared_service.remove_shared_instance(middle_child_instance) self.assertTrue( middle_child_instance.delete(), "%s-%s: Middle child instance failed to destroy" % (self.prefix, self._testMethodName)) self.assertTrue( middle_child_instance.destroyed(), "%s-%s: Middle child instance not in 'destroyed' state after timeout" % (self.prefix, self._testMethodName)) # Remove created services and last instance self.shared_service.remove_shared_instance(last_child_instance) self.assertTrue( last_child_instance.delete(), "%s-%s: Last child instance failed to destroy" % (self.prefix, self._testMethodName)) self.assertTrue( last_child_instance.destroyed(), "%s-%s: Last child instance not in 'destroyed' state after timeout" % (self.prefix, self._testMethodName))
def test_launch_3level_hierapp_shared_last_child(self): """ Launch 3-level hierarchical app with last child as shared instance. """ # Create shared last child last_child_instance = self.last_child.launch(destroyInterval=600000) self.assertTrue(last_child_instance) self.assertTrue(last_child_instance.ready()) last_child_revision = self.last_child.create_revision( name='%s-shared_last_child' % self._testMethodName, instance=last_child_instance) self.shared_service.add_shared_instance(last_child_revision, last_child_instance) parameters = { 'top_parent_in.last_child_input': 'UPD by test Hello from TOP parent to last child', 'top_parent_in.middle_child_input': 'UPD by test Hello from TOP parent to middle child', } submodules = { 'middle_child': { 'parameters': {}, 'submodules': { 'last_child': { 'revisionId': last_child_revision.revisionId } } } } parent_instance = self.parent.launch(destroyInterval=300000, parameters=parameters, submodules=submodules) self.assertTrue( parent_instance, "%s-%s: Parent instance failed to launch" % (self.prefix, self._testMethodName)) self.assertTrue( parent_instance.ready(), "%s-%s: Parent instance not in 'running' state after timeout" % (self.prefix, self._testMethodName)) self.assertTrue( parent_instance.submodules) # Check we have submodules started self.assertEqual(parent_instance.submodules[0]['status'], 'Running') middle_instance = Instance( self.context, id=parent_instance.submodules[0]['id'] ) # initialize middle instance (we can only get id from parent) self.assertTrue(middle_instance.submodules ) # Check middle instance start it's dependency self.assertEqual(middle_instance.submodules[0]['status'], 'Running') self.assertEqual(middle_instance.submodules[0]['id'], last_child_instance.instanceId, "Last child used is not shared one" ) # Check we use shared last instance self.assertTrue( parent_instance.delete(), "%s-%s: Parent instance failed to destroy" % (self.prefix, self._testMethodName)) self.assertTrue( parent_instance.destroyed(), "%s-%s: Parent instance not in 'destroyed' state after timeout" % (self.prefix, self._testMethodName)) # Remove created services and instance self.shared_service.remove_shared_instance(last_child_instance) self.assertTrue( last_child_instance.delete(), "%s-%s: Last child instance failed to destroy" % (self.prefix, self._testMethodName)) self.assertTrue( last_child_instance.destroyed(), "%s-%s: Last child instance not in 'destroyed' state after timeout" % (self.prefix, self._testMethodName))
def test_switch_last_child_shared_standalone_and_back(self): """ Launch hierarchical app with non shared instance. Change last child to shared, check. Switch back. """ # Run parent with NON shared child parent_instance = self.parent.launch(destroyInterval=3000000) self.assertTrue( parent_instance, "%s-%s: Parent instance failed to launch" % (self.prefix, self._testMethodName)) self.assertTrue( parent_instance.ready(), "%s-%s: Parent instance not in 'running' state after timeout" % (self.prefix, self._testMethodName)) non_shared_rev = self.parent.create_revision(name='non-shared-child', instance=parent_instance) middle_instance = Instance( self.context, id=parent_instance.submodules[0]['id'] ) # initialize middle instance (we can only get id from parent) # Ensure we use non shared instance self.assertEqual(middle_instance.submodules[0]['status'], 'Running') self.assertNotEqual(middle_instance.submodules[0]['id'], self.last_child_instance.instanceId) # Reconfigure parent to use shared child parameters = { 'top_parent_in.last_child_input': 'UPD by test', 'top_parent_in.middle_child_input': 'UPD by test' } submodules = { 'middle_child': { 'parameters': { 'last_child_in.app_input': 'UPD by test', 'middle_child_in.app_input': 'UPD by test' }, 'submodules': { 'last_child': { 'revisionId': self.last_child_rev.revisionId } } } } self.assertTrue( parent_instance.reconfigure(parameters=parameters, submodules=submodules)) # Check parent instance is ok self.assertTrue(parent_instance.ready(), "Instance failed to reconfigure") self.assertTrue(parent_instance.submodules, 'No submodules found') self.assertEqual(parent_instance.submodules[0]['status'], 'Running') self.assertEqual(parent_instance.submodules[0]['id'], middle_instance.instanceId) # Check last child is shared self.assertEqual(middle_instance.submodules[0]['status'], 'Running') self.assertEqual(middle_instance.submodules[0]['id'], self.last_child_instance.instanceId) # Switch back to non shared instance self.assertTrue( parent_instance.reconfigure(revisionId=non_shared_rev.revisionId)) # Check parent is ok self.assertTrue(parent_instance.ready(), "Instance failed to reconfigure") self.assertEqual(parent_instance.submodules[0]['status'], 'Running') # Check we use non-shared last child again last_instance = Instance(self.context, id=middle_instance.submodules[0]['id']) self.assertTrue(last_instance.ready()) self.assertEqual(middle_instance.submodules[0]['status'], 'Running') self.assertNotEqual(middle_instance.submodules[0]['id'], self.last_child_instance.instanceId) self.assertTrue( parent_instance.delete(), "%s-%s: Parent instance failed to destroy" % (self.prefix, self._testMethodName)) self.assertTrue( parent_instance.destroyed(), "%s-%s: Parent instance not in 'destroyed' state after timeout" % (self.prefix, self._testMethodName))
def get_instance(self, id): from qubell.api.private.instance import Instance return Instance(context=self.context, id=id)
def test_get_instance_independently(self): """ Check ways we can get existing instance """ ins = self.ins self.assertEqual(ins, Instance(self.org, ins.id))