~canonical-platform-qa/auto-upgrade-testing/qemu-desktop

« back to all changes in this revision

Viewing changes to upgrade_testing/configspec/_config.py

  • Committer: Christopher Lee
  • Date: 2015-11-06 03:50:32 UTC
  • Revision ID: chris.lee@canonical.com-20151106035032-witxxqm345pywhf8
Shuffle around module layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
import logging
20
20
import yaml
21
21
 
22
 
from upgrade_testing.provisioning import backends
23
 
 
 
22
from upgrade_testing.provisioning import ProvisionSpecification
24
23
 
25
24
logger = logging.getLogger(__name__)
26
25
 
77
76
        )
78
77
 
79
78
 
80
 
class ProvisionSpecification:
81
 
    def __init__(self):
82
 
        raise NotImplementedError()
83
 
 
84
 
    @property
85
 
    def system_states(self):
86
 
        # Note: Rename from releases
87
 
        raise NotImplementedError()
88
 
 
89
 
    @property
90
 
    def initial_state(self):
91
 
        """Return the string indicating the required initial system state."""
92
 
        raise NotImplementedError()
93
 
 
94
 
    @property
95
 
    def final_state(self):
96
 
        """Return the string indicating the required final system state."""
97
 
        raise NotImplementedError()
98
 
 
99
 
    @staticmethod
100
 
    def from_testspec(spec):
101
 
        backend_name = spec['provisioning']['backend']
102
 
        spec_type = get_specification_type(backend_name)
103
 
        return spec_type(spec['provisioning'])
104
 
 
105
 
    @staticmethod
106
 
    def from_provisionspec(spec):
107
 
        # A provision spec is almost the same as a testdef provision spec
108
 
        # except it doesn't have the parent stanza.
109
 
        backend_name = spec['backend']
110
 
        spec_type = get_specification_type(backend_name)
111
 
        return spec_type(spec)
112
 
 
113
 
 
114
 
def get_specification_type(spec_name):
115
 
    __spec_map = dict(
116
 
        lxc=LXCProvisionSpecification,
117
 
        device=DeviceProvisionSpecification
118
 
    )
119
 
    return __spec_map[spec_name]
120
 
 
121
 
 
122
 
class LXCProvisionSpecification(ProvisionSpecification):
123
 
    def __init__(self, provision_config):
124
 
        # Defaults to ubuntu
125
 
        self.distribution = provision_config.get('distribution', 'ubuntu')
126
 
        self.releases = provision_config['releases']
127
 
 
128
 
        self.backend = backends. LXCBackend(
129
 
            self.initial_state,
130
 
            self.distribution
131
 
        )
132
 
 
133
 
    @property
134
 
    def system_states(self):
135
 
        # Note: Rename from releases
136
 
        return self.releases
137
 
 
138
 
    @property
139
 
    def initial_state(self):
140
 
        """Return the string indicating the required initial system state."""
141
 
        return self.releases[0]
142
 
 
143
 
    @property
144
 
    def final_state(self):
145
 
        """Return the string indicating the required final system state."""
146
 
        return self.releases[-1]
147
 
 
148
 
    def __repr__(self):
149
 
        return '{classname}(backend={backend}, distribution={dist}, releases={releases})'.format(  # NOQA
150
 
            classname=self.__class__.__name__,
151
 
            backend=self.backend,
152
 
            dist=self.distribution,
153
 
            releases=self.releases
154
 
        )
155
 
 
156
 
 
157
 
class DeviceProvisionSpecification(ProvisionSpecification):
158
 
    def __init__(self, provision_config):
159
 
        try:
160
 
            self.channel = provision_config['channel']
161
 
            self.revisions = provision_config['revisions']
162
 
        except KeyError as e:
163
 
            raise ValueError('Missing config detail: {}'.format(str(e)))
164
 
 
165
 
        serial = provision_config.get('serial', None)
166
 
        password = provision_config.get('password', None)
167
 
        self.backend = backends.DeviceBackend(
168
 
            self.channel,
169
 
            self.initial_state,
170
 
            password,
171
 
            serial,
172
 
        )
173
 
 
174
 
    def _get_revisions(self, config):
175
 
        return [config['start-revision'], config['end-revision']]
176
 
 
177
 
    def _construct_state_string(self, rev):
178
 
        return '{channel}:{rev}'.format(channel=self.channel, rev=rev)
179
 
 
180
 
    @property
181
 
    def system_states(self):
182
 
        # Note: Rename from releases
183
 
        return [self._construct_state_string(r) for r in self.revisions]
184
 
 
185
 
    @property
186
 
    def initial_state(self):
187
 
        """Return the string indicating the required initial system state."""
188
 
        return self._construct_state_string(self.revisions[0])
189
 
 
190
 
    @property
191
 
    def final_state(self):
192
 
        """Return the string indicating the required final system state."""
193
 
        return self._construct_state_string(self.revisions[-1])
194
 
 
195
 
    def __repr__(self):
196
 
        return '{classname}(backend={backend}, channel={channel}, revisions={revisions})'.format(  # NOQA
197
 
            classname=self.__class__.__name__,
198
 
            backend=self.backend,
199
 
            channel=self.channel,
200
 
            revisions=self.system_states
201
 
        )
202
 
 
203
 
 
204
79
def definition_reader(testdef_filepath, provisiondef_filepath=None):
205
80
    """Produce a TestSpecification from the provided testdef file.
206
81