def _get_mock_schedule(schedule_id='default', next_occurrence=None, rule={'recurrence': '1 min'}, slip=0, stop_on_fail=False, latest_execution=None, enabled=True): now = utils.get_formatted_timestamp() blueprint = models.Blueprint(id='mock-bp', created_at=now, updated_at=now, main_file_name='abcd', plan={}) deployment = models.Deployment( id='mock-depl', created_at=now, updated_at=now, ) deployment.blueprint = blueprint schedule = models.ExecutionSchedule(_storage_id=1, id=schedule_id, deployment=deployment, created_at=now, since=now, until=None, rule=rule, slip=slip, workflow_id='install', parameters=None, execution_arguments={}, stop_on_fail=stop_on_fail, next_occurrence=next_occurrence or now, latest_execution=latest_execution, enabled=enabled) return schedule
def test_model_serialization(self): now = utils.get_formatted_timestamp() blueprint = models.Blueprint(id='blueprint-id', created_at=now, updated_at=now, description=None, plan={'name': 'my-bp'}, main_file_name='aaa') self.sm.put(blueprint) now2 = utils.get_formatted_timestamp() dep = models.Deployment(id='dep-id', created_at=now2, updated_at=now2, permalink=None, description=None, workflows={}, inputs={}, policy_types={}, policy_triggers={}, groups={}, scaling_groups={}, outputs={}, capabilities={}) dep.blueprint = blueprint self.sm.put(dep) serialized_dep = dep.to_response() self.assertEqual(35, len(serialized_dep)) self.assertEqual(dep.id, serialized_dep['id']) self.assertEqual(dep.created_at, serialized_dep['created_at']) self.assertEqual(dep.updated_at, serialized_dep['updated_at']) self.assertEqual(dep.blueprint_id, serialized_dep['blueprint_id']) self.assertEqual(dep.permalink, serialized_dep['permalink']) self.assertEqual(dep.tenant.name, serialized_dep['tenant_name']) self.assertEqual(dep.description, None) # `blueprint_id` isn't a regular column, but a relationship serialized_dep.pop('blueprint_id') serialized_dep.pop('tenant_name') serialized_dep.pop('created_by') serialized_dep.pop('site_name') serialized_dep.pop('latest_execution_status') serialized_dep.pop('environment_type') serialized_dep.pop('latest_execution_total_operations') serialized_dep.pop('latest_execution_finished_operations') # Deprecated columns, for backwards compatibility - # was added to the response serialized_dep.pop('resource_availability') serialized_dep.pop('private_resource') deserialized_dep = models.Deployment(**serialized_dep) self.assertEqual(dep.id, deserialized_dep.id) self.assertEqual(dep.created_at, deserialized_dep.created_at) self.assertEqual(dep.updated_at, deserialized_dep.updated_at) self.assertEqual(dep.permalink, deserialized_dep.permalink) self.assertEqual(dep.description, deserialized_dep.description)
def _put_mock_blueprint(self): blueprint_id = str(uuid.uuid4()) now = utils.get_formatted_timestamp() return self.sm.put( models.Blueprint(id=blueprint_id, created_at=now, updated_at=now, main_file_name='abcd', plan={}))
def _add_blueprint(self, blueprint_id=None): if not blueprint_id: unique_str = str(uuid.uuid4()) blueprint_id = 'blueprint-{0}'.format(unique_str) now = utils.get_formatted_timestamp() blueprint = models.Blueprint(id=blueprint_id, created_at=now, updated_at=now, description=None, plan={'name': 'my-bp'}, main_file_name='aaa') return self.sm.put(blueprint)
def test_set_parent(self): bp = models.Blueprint(id='abc') t = models.Tenant() d = models.Deployment( blueprint=bp, visibility=VisibilityState.TENANT, tenant=t, ) exc = models.Execution(deployment=d) assert exc.blueprint_id == d.blueprint_id assert exc.visibility == d.visibility assert exc.tenant == d.tenant
def test_model_serialization(self): now = utils.get_formatted_timestamp() blueprint = models.Blueprint(id='blueprint-id', created_at=now, updated_at=now, description=None, plan={'name': 'my-bp'}, main_file_name='aaa') self.sm.put(blueprint) now2 = utils.get_formatted_timestamp() dep = models.Deployment(id='dep-id', created_at=now2, updated_at=now2, permalink=None, description=None, workflows={}, inputs={}, policy_types={}, policy_triggers={}, groups={}, scaling_groups={}, outputs={}) dep.blueprint = blueprint self.sm.put(dep) serialized_dep = dep.to_response() self.assertEquals(18, len(serialized_dep)) self.assertEquals(dep.id, serialized_dep['id']) self.assertEquals(dep.created_at, serialized_dep['created_at']) self.assertEquals(dep.updated_at, serialized_dep['updated_at']) self.assertEquals(dep.blueprint_id, serialized_dep['blueprint_id']) self.assertEquals(dep.permalink, serialized_dep['permalink']) self.assertEquals(dep.tenant.name, serialized_dep['tenant_name']) self.assertEquals(dep.description, None) # `blueprint_id` isn't a regular column, but a relationship serialized_dep.pop('blueprint_id') serialized_dep.pop('tenant_name') serialized_dep.pop('created_by') serialized_dep.pop('resource_availability') deserialized_dep = models.Deployment(**serialized_dep) self.assertEquals(dep.id, deserialized_dep.id) self.assertEquals(dep.created_at, deserialized_dep.created_at) self.assertEquals(dep.updated_at, deserialized_dep.updated_at) self.assertEquals(dep.permalink, deserialized_dep.permalink) self.assertEquals(dep.description, deserialized_dep.description)
def test_fields_query(self): now = utils.get_formatted_timestamp() blueprint = models.Blueprint(id='blueprint-id', created_at=now, updated_at=now, description=None, plan={'name': 'my-bp'}, main_file_name='aaa') self.sm.put(blueprint) blueprint_restored = self.sm.get(models.Blueprint, 'blueprint-id', include=['id', 'created_at']) self.assertEquals('blueprint-id', blueprint_restored.id) self.assertEquals(now, blueprint_restored.created_at) self.assertFalse(hasattr(blueprint_restored, 'updated_at')) self.assertFalse(hasattr(blueprint_restored, 'plan')) self.assertFalse(hasattr(blueprint_restored, 'main_file_name'))
def test_store_load_delete_blueprint(self): now = utils.get_formatted_timestamp() blueprint = models.Blueprint(id='blueprint-id', created_at=now, updated_at=now, description=None, plan={'name': 'my-bp'}, main_file_name='aaa') self.sm.put(blueprint) blueprint_from_list = self.sm.list(models.Blueprint)[0] blueprint_restored = self.sm.get(models.Blueprint, 'blueprint-id') bp_from_delete = self.sm.delete(blueprint_restored) self.assertEquals(blueprint.to_dict(), blueprint_from_list.to_dict()) self.assertEquals(blueprint.to_dict(), blueprint_restored.to_dict()) # in bp returned from delete operation only 'id' is guaranteed to # return self.assertEquals(blueprint.id, bp_from_delete.id) blueprints_list = self.sm.list(models.Blueprint) self.assertEquals(0, len(blueprints_list))
def setUp(self): super().setUp() bp = models.Blueprint(id='abc') self.sm.put(bp) self.deployment1 = models.Deployment(id='dep1', display_name='dep1', blueprint=bp) self.sm.put(self.deployment1) self.deployment2 = models.Deployment(id='dep2', display_name='dep2', blueprint=bp) self.sm.put(self.deployment2) self.execution1 = models.Execution( deployment=self.deployment1, workflow_id='install', parameters={}, status=ExecutionState.TERMINATED, ) self.sm.put(self.execution1)
def test_get_blueprint_deployments(self): now = utils.get_formatted_timestamp() blueprint = models.Blueprint(id='blueprint-id', created_at=now, updated_at=now, description=None, plan={'name': 'my-bp'}, main_file_name='aaa') another_blueprint = models.Blueprint(id='another-blueprint-id', created_at=now, updated_at=now, description=None, plan={'name': 'my-bp'}, main_file_name='aaa') self.sm.put(blueprint) self.sm.put(another_blueprint) deployment1 = models.Deployment(id='dep-1', created_at=now, updated_at=now, permalink=None, description=None, workflows={}, inputs={}, policy_types={}, policy_triggers={}, groups={}, scaling_groups={}, outputs={}) deployment1.blueprint = blueprint self.sm.put(deployment1) deployment2 = models.Deployment(id='dep-2', created_at=now, updated_at=now, permalink=None, description=None, workflows={}, inputs={}, policy_types={}, policy_triggers={}, groups={}, scaling_groups={}, outputs={}) deployment2.blueprint = blueprint self.sm.put(deployment2) deployment3 = models.Deployment(id='dep-3', created_at=now, updated_at=now, description=None, permalink=None, workflows={}, inputs={}, policy_types={}, policy_triggers={}, groups={}, scaling_groups={}, outputs={}) deployment3.blueprint = another_blueprint self.sm.put(deployment3) filters_bp = {'blueprint_id': 'blueprint-id'} blueprint_deployments = \ self.sm.list(models.Deployment, filters=filters_bp) self.assertEquals(2, len(blueprint_deployments)) if blueprint_deployments[0].id != deployment1.id: blueprint_deployments[0], blueprint_deployments[1] =\ blueprint_deployments[1], blueprint_deployments[0] self.assertEquals(deployment1.to_dict(), blueprint_deployments[0].to_dict()) self.assertEquals(deployment2.to_dict(), blueprint_deployments[1].to_dict())
def _restore_blueprints(self): for line in open(self._blueprints_path, 'r'): elem = self._get_elem(line) blueprint = models.Blueprint(**elem) self._storage_manager.put(blueprint)