80
class ProvisionSpecification:
82
raise NotImplementedError()
85
def system_states(self):
86
# Note: Rename from releases
87
raise NotImplementedError()
90
def initial_state(self):
91
"""Return the string indicating the required initial system state."""
92
raise NotImplementedError()
95
def final_state(self):
96
"""Return the string indicating the required final system state."""
97
raise NotImplementedError()
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'])
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)
114
def get_specification_type(spec_name):
116
lxc=LXCProvisionSpecification,
117
device=DeviceProvisionSpecification
119
return __spec_map[spec_name]
122
class LXCProvisionSpecification(ProvisionSpecification):
123
def __init__(self, provision_config):
125
self.distribution = provision_config.get('distribution', 'ubuntu')
126
self.releases = provision_config['releases']
128
self.backend = backends. LXCBackend(
134
def system_states(self):
135
# Note: Rename from releases
139
def initial_state(self):
140
"""Return the string indicating the required initial system state."""
141
return self.releases[0]
144
def final_state(self):
145
"""Return the string indicating the required final system state."""
146
return self.releases[-1]
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
157
class DeviceProvisionSpecification(ProvisionSpecification):
158
def __init__(self, provision_config):
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)))
165
serial = provision_config.get('serial', None)
166
password = provision_config.get('password', None)
167
self.backend = backends.DeviceBackend(
174
def _get_revisions(self, config):
175
return [config['start-revision'], config['end-revision']]
177
def _construct_state_string(self, rev):
178
return '{channel}:{rev}'.format(channel=self.channel, rev=rev)
181
def system_states(self):
182
# Note: Rename from releases
183
return [self._construct_state_string(r) for r in self.revisions]
186
def initial_state(self):
187
"""Return the string indicating the required initial system state."""
188
return self._construct_state_string(self.revisions[0])
191
def final_state(self):
192
"""Return the string indicating the required final system state."""
193
return self._construct_state_string(self.revisions[-1])
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
204
79
def definition_reader(testdef_filepath, provisiondef_filepath=None):
205
80
"""Produce a TestSpecification from the provided testdef file.