def test_model_serialization(self):
        dep = models.Deployment(id='dep-id',
                                created_at='some-time1',
                                updated_at='some-time2',
                                blueprint_id='bp-id',
                                permalink=None,
                                description=None,
                                workflows={},
                                inputs={},
                                policy_types={},
                                policy_triggers={},
                                groups={},
                                scaling_groups={},
                                outputs={})

        serialized_dep = dep.to_dict()
        self.assertEquals(13, 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.description, None)

        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.blueprint_id, deserialized_dep.blueprint_id)
        self.assertEquals(dep.permalink, deserialized_dep.permalink)
        self.assertEquals(dep.description, deserialized_dep.description)
    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)
Beispiel #3
0
    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)
Beispiel #4
0
 def _restore_deployments(self):
     for line in open(self._deployments_path, 'r'):
         dep_dict = self._get_elem(line)
         blueprint = self._update_deployment(dep_dict)
         deployment = models.Deployment(**dep_dict)
         deployment.blueprint = blueprint
         self._storage_manager.put(deployment)
Beispiel #5
0
 def test_allow_undeclared_parameters(self):
     d = models.Deployment(workflows={'wf': {}})
     exc = models.Execution(parameters={'param1': 'abc'},
                            deployment=d,
                            workflow_id='wf',
                            allow_custom_parameters=True)
     assert exc.parameters == {'param1': 'abc'}
Beispiel #6
0
 def test_override_default_params(self):
     d = models.Deployment(
         workflows={
             'wf': {
                 'parameters': {
                     'param1': {
                         'default': 'abc'
                     },
                     'param2': {
                         'default': {
                             'nested': 'abc'
                         }
                     }
                 }
             }
         })
     exc = models.Execution(
         parameters={
             'param1': 'bcd',
             'param2': {
                 'nested': 'bcd'
             }
         },
         deployment=d,
         workflow_id='wf',
     )
     assert exc.parameters == {'param1': 'bcd', 'param2': {'nested': 'bcd'}}
Beispiel #7
0
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
Beispiel #8
0
 def test_missing_workflow(self):
     d = models.Deployment(workflows={'wf': {}})
     with self.assertRaises(manager_exceptions.NonexistentWorkflowError):
         models.Execution(
             parameters={},
             deployment=d,
             workflow_id='nonexistent',
         )
Beispiel #9
0
 def _get_mock_deployment(deployment_id, blueprint):
     now = utils.get_formatted_timestamp()
     deployment = models.Deployment(
         id=deployment_id,
         created_at=now,
         updated_at=now,
     )
     deployment.blueprint = blueprint
     return deployment
Beispiel #10
0
 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)
Beispiel #11
0
 def test_undeclared_parameters(self):
     d = models.Deployment(workflows={'wf': {}})
     with self.assertRaisesRegex(
             manager_exceptions.IllegalExecutionParametersError,
             'custom parameters',
     ):
         models.Execution(
             parameters={'param1': 'abc'},
             deployment=d,
             workflow_id='wf',
         )
Beispiel #12
0
 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
Beispiel #13
0
 def test_missing_mandatory_param(self):
     d = models.Deployment(
         workflows={'wf': {
             'parameters': {
                 'mandatory_param': {}
             }
         }})
     with self.assertRaisesRegex(
             manager_exceptions.IllegalExecutionParametersError,
             'mandatory_param'):
         models.Execution(
             parameters={},
             deployment=d,
             workflow_id='wf',
         )
Beispiel #14
0
 def test_use_default_params(self):
     d = models.Deployment(
         workflows={'wf': {
             'parameters': {
                 'param1': {
                     'default': 'abc'
                 }
             }
         }})
     exc = models.Execution(
         parameters={},
         deployment=d,
         workflow_id='wf',
     )
     assert exc.parameters == {'param1': 'abc'}
Beispiel #15
0
 def _add_deployment(self, blueprint, deployment_id=None):
     if not deployment_id:
         unique_str = str(uuid.uuid4())
         deployment_id = 'deployment-{0}'.format(unique_str)
     now = utils.get_formatted_timestamp()
     deployment = models.Deployment(id=deployment_id,
                                    created_at=now,
                                    updated_at=now,
                                    permalink=None,
                                    description=None,
                                    workflows={},
                                    inputs={},
                                    policy_types={},
                                    policy_triggers={},
                                    groups={},
                                    scaling_groups={},
                                    outputs={})
     deployment.blueprint = blueprint
     return self.sm.put(deployment)
Beispiel #16
0
 def test_parameters_type_conversion(self):
     d = models.Deployment(
         workflows={
             'wf': {
                 'parameters': {
                     'bool_param': {
                         'type': 'boolean'
                     },
                     'int_param': {
                         'type': 'integer'
                     },
                     'float_param': {
                         'type': 'float'
                     },
                     'string_param': {
                         'type': 'string'
                     },
                     'untyped_param': {}
                 }
             }
         })
     exc = models.Execution(
         parameters={
             'bool_param': 'true',
             'int_param': '5',
             'float_param': '1.5',
             'string_param': 'abc',
             'untyped_param': 'def',
         },
         deployment=d,
         workflow_id='wf',
     )
     assert exc.parameters == {
         'bool_param': True,
         'int_param': 5,
         'float_param': 1.5,
         'string_param': 'abc',
         'untyped_param': 'def'
     }
Beispiel #17
0
    def test_parameters_wrong_type(self):
        d = models.Deployment(
            workflows={
                'wf': {
                    'parameters': {
                        'bool_param': {
                            'type': 'boolean',
                            'default': True
                        },
                        'int_param': {
                            'type': 'integer',
                            'default': 5
                        },
                        'float_param': {
                            'type': 'float',
                            'default': 5.0
                        },
                    }
                }
            })
        with self.assertRaises(
                manager_exceptions.IllegalExecutionParametersError) as cm:
            models.Execution(
                parameters={
                    'bool_param': 'abc',
                    'int_param': 'abc',
                    'float_param': 'abc',
                },
                deployment=d,
                workflow_id='wf',
            )

        error_message = str(cm.exception)
        assert 'bool_param' in error_message
        assert 'int_param' in error_message
        assert 'float_param' in error_message
Beispiel #18
0
    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())