Ejemplo n.º 1
0
    def setUp(self, *args, **kwargs):
        super(TestServerTemplateActor, self).setUp()
        base.TOKEN = 'unittest'

        # Create some fake image reference objects
        self._images = [
            {'mci': 'imageA', 'rev': 1, 'is_default': True},
            {'mci': 'imageB', 'is_default': False},
            {'mci': 'imageC'}
        ]

        self._boot_bindings = [
            {'right_script': 'bootA', 'rev': 0},
            {'right_script': 'bootB', 'rev': 0},
        ]
        self._operational_bindings = [
            {'right_script': 'operationalA', 'rev': 0},
            {'right_script': 'operationalB', 'rev': 0},
        ]
        self._decommission_bindings = [
            {'right_script': 'decommissionA', 'rev': 0},
            {'right_script': 'decommissionB', 'rev': 0},
        ]
        self._alerts = [
            {'name': 'Instance Stranded',
             'description': 'Alert if an instance enders a stranded',
             'file': 'RS/server-failure',
             'variable': 'state',
             'condition': '==',
             'threshold': 'stranded',
             'duration': 2,
             'escalation_name': 'critical'}
        ]

        # Create the actor
        self.actor = server_template.ServerTemplate(
            options={
                'name': 'testst',
                'state': 'present',
                'commit': 'Yeah, committed',
                'tags': ['tag'],
                'description': 'test st desc',
                'images': self._images,
                'boot_bindings': self._boot_bindings,
                'operational_bindings': self._operational_bindings,
                'decommission_bindings': self._decommission_bindings,
                'alerts': self._alerts,
            })

        # Patch the actor so that we use the client mock
        self.client_mock = mock.MagicMock(name='client')
        self.actor._client = self.client_mock

        # Pre-populate our cached Server Template information for the purposes
        # of most of the tests. We start with some basic defaults, and then our
        # tests below will try changing these.
        self.actor.st = mock.MagicMock(name='server_template_a')
        self.actor.st.href = '/api/server_templates/test'
        self.actor.st.links = {
            'self': '/api/server_templates/xxx',
            'default_multi_cloud_image': '/api/multi_cloud_images/imageA',
            'inputs': '/api/server_templates/xxx/inputs',
            'alert_specs': '/api/server_templates/xxx/alert_specs',
            'runnable_bindings': '/api/server_templates/xxx/runnable_bindings',
            'cookbook_attachments':
                '/api/server_templates/xxx/cookbook_attachments'
        }
        self.actor.st.soul = {
            'actions': [
                {'rel': 'commit'},
                {'rel': 'clone'},
                {'rel': 'resolve'},
                {'rel': 'swap_repository'},
                {'rel': 'detect_changes_in_head'}
            ],
            'description': 'Fake desc',
            'lineage': 'https://fake.com/api/acct/xx/ec3_server_templates/xxx',
            'links': [
                {'href': '/api/server_templates/xxx',
                 'rel': 'self'},
                {'href': '/api/server_templates/xxx/multi_cloud_images',
                 'rel': 'multi_cloud_images'},
                {'href': '/api/multi_cloud_images/imageA',
                 'rel': 'default_multi_cloud_image'},
                {'href': '/api/server_templates/xxx/inputs',
                 'rel': 'inputs'},
                {'href': '/api/server_templates/xxx/alert_specs',
                 'rel': 'alert_specs'},
                {'href': '/api/server_templates/xxx/runnable_bindings',
                 'rel': 'runnable_bindings'},
                {'href': '/api/server_templates/xxx/cookbook_attachments',
                 'rel': 'cookbook_attachments'}
            ],
            'name': 'Test ServerTemplate',
            'revision': 0
        }
        self.actor.tags = ['tag1', 'tag2']
        self.actor.desired_images = {
            '/api/multi_cloud_images/imageA': {
                'default': True
            },
            '/api/multi_cloud_images/imageB': {
                'default': False
            },
            '/api/multi_cloud_images/imageC': {
                'default': False
            }
        }
        self.actor.images = {
            '/api/multi_cloud_images/imageD': {
                'default': True,
                'map_href': '/api/st_mci/imageD',
                'map_obj': mock.MagicMock(name='imaged_map')
            }
        }

        # For most tests, pretend we have no bindings at all
        self.actor.boot_bindings = []
        self.actor.operational_bindings = []
        self.actor._bindings = []

        # Pretend though that we were able to populate our desired bindings
        # with real HREFs.
        self.actor.desired_boot_bindings = [
            {'position': 0,
             'right_script_href': '/api/binding/bootA',
             'sequence': 'boot'},
            {'position': 1,
             'right_script_href': '/api/binding/bootB',
             'sequence': 'boot'},
        ]
        self.actor.desired_operational_bindings = [
            {'position': 0,
             'right_script_href': '/api/binding/operationalA',
             'sequence': 'operational'},
            {'position': 1,
             'right_script_href': '/api/binding/operationalB',
             'sequence': 'operational'},
        ]
        self.actor.desired_decommission_bindings = [
            {'position': 0,
             'right_script_href': '/api/binding/decommissionA',
             'sequence': 'decommission'},
            {'position': 1,
             'right_script_href': '/api/binding/decommissionB',
             'sequence': 'decommission'},
        ]
Ejemplo n.º 2
0
 def integration_06a_delete_st(self):
     self.template['state'] = 'absent'
     actor = server_template.ServerTemplate(
         options=self.template)
     yield actor.execute()
Ejemplo n.º 3
0
 def integration_05b_create_st(self):
     actor = server_template.ServerTemplate(
         options=self.template)
     yield actor.execute()
Ejemplo n.º 4
0
 def integration_05c_update_st(self):
     self.template['alerts'][0]['duration'] = 5
     actor = server_template.ServerTemplate(
         options=self.template)
     yield actor.execute()
Ejemplo n.º 5
0
 def integration_05a_create_st_dry(self):
     actor = server_template.ServerTemplate(
         options=self.template,
         dry=True)
     yield actor.execute()