~ubuntu-branches/ubuntu/wily/heat/wily-proposed

« back to all changes in this revision

Viewing changes to heat_integrationtests/scenario/test_server_software_config.py

  • Committer: Package Import Robot
  • Author(s): James Page, Corey Bryant, James Page
  • Date: 2015-03-30 11:11:18 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20150330111118-2qpycylx6swu4yhj
Tags: 2015.1~b3-0ubuntu1
[ Corey Bryant ]
* New upstream milestone release for OpenStack kilo:
  - d/control: Align with upstream dependencies.
  - d/p/sudoers_patch.patch: Rebased.
  - d/p/fix-requirements.patch: Rebased.

[ James Page ]
* d/p/fixup-assert-regex.patch: Tweak test to use assertRegexpMatches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
2
#    not use this file except in compliance with the License. You may obtain
 
3
#    a copy of the License at
 
4
#
 
5
#         http://www.apache.org/licenses/LICENSE-2.0
 
6
#
 
7
#    Unless required by applicable law or agreed to in writing, software
 
8
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
9
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
10
#    License for the specific language governing permissions and limitations
 
11
#    under the License.
 
12
 
 
13
from heatclient.common import template_utils
 
14
import six
 
15
 
 
16
from heat_integrationtests.common import exceptions
 
17
from heat_integrationtests.scenario import scenario_base
 
18
 
 
19
CFG1_SH = '''#!/bin/sh
 
20
echo "Writing to /tmp/$bar"
 
21
echo $foo > /tmp/$bar
 
22
echo -n "The file /tmp/$bar contains `cat /tmp/$bar` for server \
 
23
$deploy_server_id during $deploy_action" > $heat_outputs_path.result
 
24
echo "Written to /tmp/$bar"
 
25
echo "Output to stderr" 1>&2
 
26
'''
 
27
 
 
28
CFG3_PP = '''file {'barfile':
 
29
  ensure  => file,
 
30
  mode    => 0644,
 
31
  path    => "/tmp/$::bar",
 
32
  content => "$::foo",
 
33
}
 
34
file {'output_result':
 
35
  ensure  => file,
 
36
  path    => "$::heat_outputs_path.result",
 
37
  mode    => 0644,
 
38
  content => "The file /tmp/$::bar contains $::foo for server \
 
39
$::deploy_server_id during $::deploy_action",
 
40
}'''
 
41
 
 
42
 
 
43
class SoftwareConfigIntegrationTest(scenario_base.ScenarioTestsBase):
 
44
 
 
45
    def setUp(self):
 
46
        super(SoftwareConfigIntegrationTest, self).setUp()
 
47
        if self.conf.skip_software_config_tests:
 
48
            self.skipTest('Testing software config disabled in conf, '
 
49
                          'skipping')
 
50
        self.stack_name = self._stack_rand_name()
 
51
 
 
52
    def check_stack(self):
 
53
        sid = self.stack_identifier
 
54
        # Check that all stack resources were created
 
55
        for res in ('cfg2a', 'cfg2b', 'cfg1', 'cfg3', 'server'):
 
56
            self._wait_for_resource_status(
 
57
                sid, res, 'CREATE_COMPLETE')
 
58
 
 
59
        server_resource = self.client.resources.get(sid, 'server')
 
60
        server_id = server_resource.physical_resource_id
 
61
        server = self.compute_client.servers.get(server_id)
 
62
 
 
63
        # Waiting for each deployment to contribute their
 
64
        # config to resource
 
65
        try:
 
66
            for res in ('dep2b', 'dep1', 'dep3'):
 
67
                self._wait_for_resource_status(
 
68
                    sid, res, 'CREATE_IN_PROGRESS')
 
69
 
 
70
            server_metadata = self.client.resources.metadata(
 
71
                sid, 'server')
 
72
            deployments = dict((d['name'], d) for d in
 
73
                               server_metadata['deployments'])
 
74
 
 
75
            for res in ('dep2a', 'dep2b', 'dep1', 'dep3'):
 
76
                self._wait_for_resource_status(
 
77
                    sid, res, 'CREATE_COMPLETE')
 
78
        except (exceptions.StackResourceBuildErrorException,
 
79
                exceptions.TimeoutException) as e:
 
80
            self._log_console_output(servers=[server])
 
81
            raise e
 
82
 
 
83
        # Check that stack was fully created
 
84
        self._wait_for_stack_status(sid, 'CREATE_COMPLETE')
 
85
 
 
86
        complete_server_metadata = self.client.resources.metadata(
 
87
            sid, 'server')
 
88
 
 
89
        # Ensure any previously available deployments haven't changed so
 
90
        # config isn't re-triggered
 
91
        complete_deployments = dict((d['name'], d) for d in
 
92
                                    complete_server_metadata['deployments'])
 
93
        for k, v in six.iteritems(deployments):
 
94
            self.assertEqual(v, complete_deployments[k])
 
95
 
 
96
        stack = self.client.stacks.get(sid)
 
97
 
 
98
        res1 = self._stack_output(stack, 'res1')
 
99
        self.assertEqual(
 
100
            'The file %s contains %s for server %s during %s' % (
 
101
                '/tmp/baaaaa', 'fooooo', server_id, 'CREATE'),
 
102
            res1['result'])
 
103
        self.assertEqual(0, res1['status_code'])
 
104
        self.assertEqual('Output to stderr\n', res1['stderr'])
 
105
        self.assertTrue(len(res1['stdout']) > 0)
 
106
 
 
107
        res2 = self._stack_output(stack, 'res2')
 
108
        self.assertEqual(
 
109
            'The file %s contains %s for server %s during %s' % (
 
110
                '/tmp/cfn-init-foo', 'barrr', server_id, 'CREATE'),
 
111
            res2['result'])
 
112
        self.assertEqual(0, res2['status_code'])
 
113
        self.assertEqual('', res2['stderr'])
 
114
        self.assertEqual('', res2['stdout'])
 
115
 
 
116
        res3 = self._stack_output(stack, 'res3')
 
117
        self.assertEqual(
 
118
            'The file %s contains %s for server %s during %s' % (
 
119
                '/tmp/ba', 'fo', server_id, 'CREATE'),
 
120
            res3['result'])
 
121
        self.assertEqual(0, res3['status_code'])
 
122
        self.assertEqual('', res3['stderr'])
 
123
        self.assertTrue(len(res1['stdout']) > 0)
 
124
 
 
125
        dep1_resource = self.client.resources.get(sid, 'dep1')
 
126
        dep1_id = dep1_resource.physical_resource_id
 
127
        dep1_dep = self.client.software_deployments.get(dep1_id)
 
128
        if hasattr(dep1_dep, 'updated_time'):
 
129
            # Only check updated_time if the attribute exists.
 
130
            # This allows latest heat agent code to be tested with
 
131
            # Juno heat (which doesn't expose updated_time)
 
132
            self.assertIsNotNone(dep1_dep.updated_time)
 
133
            self.assertNotEqual(
 
134
                dep1_dep.updated_time,
 
135
                dep1_dep.creation_time)
 
136
 
 
137
    def test_server_software_config(self):
 
138
        """
 
139
        Check that passed files with scripts are executed on created server.
 
140
 
 
141
        The alternative scenario is the following:
 
142
            1. Create a stack and pass files with scripts.
 
143
            2. Check that all stack resources are created successfully.
 
144
            3. Wait for all deployments.
 
145
            4. Check that stack was created.
 
146
            5. Check stack outputs.
 
147
        """
 
148
 
 
149
        parameters = {
 
150
            'key_name': self.keypair_name,
 
151
            'flavor': self.conf.instance_type,
 
152
            'image': self.conf.image_ref,
 
153
            'network': self.net['id']
 
154
        }
 
155
 
 
156
        files = {
 
157
            'cfg1.sh': CFG1_SH,
 
158
            'cfg3.pp': CFG3_PP
 
159
        }
 
160
 
 
161
        env_files, env = template_utils.process_environment_and_files(
 
162
            self.conf.boot_config_env)
 
163
 
 
164
        # Launch stack
 
165
        self.stack_identifier = self.launch_stack(
 
166
            stack_name=self.stack_name,
 
167
            template_name='test_server_software_config.yaml',
 
168
            parameters=parameters,
 
169
            files=dict(list(files.items()) + list(env_files.items())),
 
170
            expected_status=None,
 
171
            environment=env
 
172
        )
 
173
 
 
174
        # Check stack
 
175
        self.check_stack()