~veebers/juju-ci-tools/model_migration_check_all_units_of_charm

1566.1.1 by Leo Zhang
Add assess_constraints
1
#!/usr/bin/env python
1566.1.2 by Leo Zhang
Changes after review.
2
"""This module tests the deployment with constraints."""
1566.1.1 by Leo Zhang
Add assess_constraints
3
4
from __future__ import print_function
5
import argparse
6
import logging
1587.1.20 by Andrew Beach
More fixes and improvement from the inline comments of my last request.
7
import os
1566.1.1 by Leo Zhang
Add assess_constraints
8
import sys
1587.1.23 by Andrew Beach
Folded in my old changes and got an instance-type test running and passing.
9
import re
10
1566.1.1 by Leo Zhang
Add assess_constraints
11
from deploy_stack import (
12
    BootstrapManager,
1587.1.3 by Andrew Beach
Moved the generic set up for deploy_constraints into a helper function.
13
    )
1566.1.1 by Leo Zhang
Add assess_constraints
14
from jujucharm import (
15
    Charm,
16
    local_charm_path,
1587.1.3 by Andrew Beach
Moved the generic set up for deploy_constraints into a helper function.
17
    )
1566.1.1 by Leo Zhang
Add assess_constraints
18
from utility import (
19
    add_basic_testing_arguments,
20
    configure_logging,
21
    JujuAssertionError,
22
    temp_dir,
1587.1.3 by Andrew Beach
Moved the generic set up for deploy_constraints into a helper function.
23
    )
1566.1.1 by Leo Zhang
Add assess_constraints
24
25
26
__metaclass__ = type
27
28
29
log = logging.getLogger("assess_constraints")
30
1566.1.2 by Leo Zhang
Changes after review.
31
VIRT_TYPES = ['lxd']
1566.1.1 by Leo Zhang
Add assess_constraints
32
1587.1.6 by Andrew Beach
Began adding new instance-type contraint testing code and the approprate unit tests.
33
INSTANCE_TYPES = {
34
    'azure': [],
1587.1.16 by Andrew Beach
Completed tests, used Constraints to replace make_constraints. Finished the first draft of the initial tests (have not been checked).
35
    'ec2': ['t2.micro'],
1587.1.6 by Andrew Beach
Began adding new instance-type contraint testing code and the approprate unit tests.
36
    'gce': [],
37
    'joyent': [],
38
    'openstack': [],
39
    }
40
1566.1.1 by Leo Zhang
Add assess_constraints
41
1587.1.15 by Andrew Beach
Merged constraints.py into [tests/test_]assess_constraints.py. Adding the approprate testing.
42
# This assumes instances are unique accross providers.
43
def get_instance_spec(instance_type):
44
    """Get the specifications of a given instance type."""
45
    return {
1587.1.26 by Andrew Beach
Now we fail if the instance-type is not met and fixed the t2.micro finger-print.
46
        't2.micro': {'mem': '1G', 'cpu-power': '10', 'cores': '1'},
1587.1.15 by Andrew Beach
Merged constraints.py into [tests/test_]assess_constraints.py. Adding the approprate testing.
47
        }[instance_type]
48
49
1587.1.23 by Andrew Beach
Folded in my old changes and got an instance-type test running and passing.
50
def mem_to_int(size):
51
    """Convert an argument size into a number of megabytes."""
52
    if not re.match(re.compile('^[0123456789]+[MGTP]?$'), size):
53
        raise JujuAssertionError('Not a size format:', size)
54
    if size[-1] in 'MGTP':
55
        val = int(size[0:-1])
56
        unit = size[-1]
57
        return val * (1024 ** 'MGTP'.find(unit))
58
    else:
59
        return int(size)
60
61
1587.1.15 by Andrew Beach
Merged constraints.py into [tests/test_]assess_constraints.py. Adding the approprate testing.
62
class Constraints:
1587.1.20 by Andrew Beach
More fixes and improvement from the inline comments of my last request.
63
    """Class that represents a set of contraints."""
1587.1.15 by Andrew Beach
Merged constraints.py into [tests/test_]assess_constraints.py. Adding the approprate testing.
64
65
    @staticmethod
66
    def _list_to_str(constraints_list):
1587.1.20 by Andrew Beach
More fixes and improvement from the inline comments of my last request.
67
        parts = ['{}={}'.format(name, value) for (name, value) in
68
                 constraints_list if value is not None]
1587.1.15 by Andrew Beach
Merged constraints.py into [tests/test_]assess_constraints.py. Adding the approprate testing.
69
        return ' '.join(parts)
70
1645.1.1 by Andrew Beach
Added a __repr__ operator to Constraints for debugging.
71
    def _get_constraint_pairs(self):
72
        """Get a list of (constraint-name, constraint-value) pairs."""
73
        return [('mem', self.mem), ('cores', self.cores),
74
                ('virt-type', self.virt_type),
75
                ('instance-type', self.instance_type),
76
                ('root-disk', self.root_disk), ('cpu-power', self.cpu_power),
77
                ('arch', self.arch),
78
                ]
79
1587.1.15 by Andrew Beach
Merged constraints.py into [tests/test_]assess_constraints.py. Adding the approprate testing.
80
    def __init__(self, mem=None, cores=None, virt_type=None,
1587.1.16 by Andrew Beach
Completed tests, used Constraints to replace make_constraints. Finished the first draft of the initial tests (have not been checked).
81
                 instance_type=None, root_disk=None, cpu_power=None,
82
                 arch=None):
83
        """Create a new constraints instance from individual constraints."""
1587.1.15 by Andrew Beach
Merged constraints.py into [tests/test_]assess_constraints.py. Adding the approprate testing.
84
        self.mem = mem
85
        self.cores = cores
86
        self.virt_type = virt_type
87
        self.instance_type = instance_type
88
        self.root_disk = root_disk
89
        self.cpu_power = cpu_power
1587.1.16 by Andrew Beach
Completed tests, used Constraints to replace make_constraints. Finished the first draft of the initial tests (have not been checked).
90
        self.arch = arch
1587.1.15 by Andrew Beach
Merged constraints.py into [tests/test_]assess_constraints.py. Adding the approprate testing.
91
1645.1.1 by Andrew Beach
Added a __repr__ operator to Constraints for debugging.
92
    def __repr__(self):
93
        """Get a detailed string reperentation of the object."""
94
        pairs = self._get_constraint_pairs()
95
        parts = ['{}={!r}'.format(name.replace('-', '_'), value)
96
                 for (name, value) in pairs if value is not None]
97
        return 'Constraints({})'.format(', '.join(parts))
98
1587.1.15 by Andrew Beach
Merged constraints.py into [tests/test_]assess_constraints.py. Adding the approprate testing.
99
    def __str__(self):
100
        """Convert the instance constraint values into an argument string."""
1645.1.1 by Andrew Beach
Added a __repr__ operator to Constraints for debugging.
101
        return Constraints._list_to_str(self._get_constraint_pairs())
1587.1.15 by Andrew Beach
Merged constraints.py into [tests/test_]assess_constraints.py. Adding the approprate testing.
102
1587.1.16 by Andrew Beach
Completed tests, used Constraints to replace make_constraints. Finished the first draft of the initial tests (have not been checked).
103
    def __eq__(self, other):
1587.1.18 by Andrew Beach
Fixed to the lint standard.
104
        return (self.mem == other.mem and self.cores == other.cores and
105
                self.virt_type == other.virt_type and
106
                self.instance_type == other.instance_type and
107
                self.root_disk == other.root_disk and
108
                self.cpu_power == other.cpu_power and
109
                self.arch == other.arch
1587.1.16 by Andrew Beach
Completed tests, used Constraints to replace make_constraints. Finished the first draft of the initial tests (have not been checked).
110
                )
111
1587.1.23 by Andrew Beach
Folded in my old changes and got an instance-type test running and passing.
112
    @staticmethod
113
    def _meets_string(constraint, actual):
114
        if constraint is None:
115
            return True
1587.1.37 by Andrew Beach
Added tools to create more generic constraints tests.
116
        if actual is None:
117
            return False
1587.1.23 by Andrew Beach
Folded in my old changes and got an instance-type test running and passing.
118
        return constraint == actual
119
120
    @staticmethod
121
    def _meets_min_int(constraint, actual):
122
        if constraint is None:
123
            return True
1587.1.37 by Andrew Beach
Added tools to create more generic constraints tests.
124
        if actual is None:
125
            return False
1587.1.23 by Andrew Beach
Folded in my old changes and got an instance-type test running and passing.
126
        return int(constraint) <= int(actual)
127
128
    @staticmethod
129
    def _meets_min_mem(constraint, actual):
130
        if constraint is None:
131
            return True
1587.1.37 by Andrew Beach
Added tools to create more generic constraints tests.
132
        if actual is None:
133
            return False
1587.1.23 by Andrew Beach
Folded in my old changes and got an instance-type test running and passing.
134
        return mem_to_int(constraint) <= mem_to_int(actual)
135
136
    def meets_root_disk(self, actual_root_disk):
137
        """Check to see if a given value meets the root_disk constraint."""
138
        return self._meets_min_mem(self.root_disk, actual_root_disk)
139
140
    def meets_cores(self, actual_cores):
141
        """Check to see if a given value meets the cores constraint."""
142
        return self._meets_min_int(self.cores, actual_cores)
143
144
    def meets_cpu_power(self, actual_cpu_power):
145
        """Check to see if a given value meets the cpu_power constraint."""
146
        return self._meets_min_int(self.cpu_power, actual_cpu_power)
147
148
    def meets_arch(self, actual_arch):
149
        """Check to see if a given value meets the arch constraint."""
150
        return self._meets_string(self.arch, actual_arch)
151
152
    def meets_instance_type(self, actual_data):
153
        """Check to see if a given value meets the instance_type constraint.
154
155
        Currently there is no direct way to check for it, so we 'fingerprint'
156
        each instance_type in a dictionary."""
1587.1.37 by Andrew Beach
Added tools to create more generic constraints tests.
157
        if self.instance_type is None:
158
            return True
1587.1.23 by Andrew Beach
Folded in my old changes and got an instance-type test running and passing.
159
        instance_data = get_instance_spec(self.instance_type)
160
        for (key, value) in instance_data.iteritems():
161
            # Temperary fix until cpu-cores -> cores switch is finished.
162
            if key is 'cores' and 'cpu-cores' in actual_data:
163
                key = 'cpu-cores'
164
            if key not in actual_data:
165
                raise JujuAssertionError('Missing data:', key)
166
            elif key in ['mem', 'root-disk']:
167
                if mem_to_int(value) != mem_to_int(actual_data[key]):
168
                    return False
169
            elif value != actual_data[key]:
170
                return False
171
        else:
172
            return True
173
1587.1.37 by Andrew Beach
Added tools to create more generic constraints tests.
174
    def meets_all(self, actual_data):
175
        return (self.meets_root_disk(actual_data.get('root-disk')) and
176
                self.meets_cores(actual_data.get('cores')) and
177
                self.meets_cpu_power(actual_data.get('cpu-power')) and
178
                self.meets_arch(actual_data.get('arch')) and
179
                self.meets_instance_type(actual_data))
180
1587.1.15 by Andrew Beach
Merged constraints.py into [tests/test_]assess_constraints.py. Adding the approprate testing.
181
1587.1.10 by Andrew Beach
Added new code to support more asserts in assess_constraints. Mostly around juju_show_machine_hardware.
182
def deploy_constraint(client, constraints, charm, series, charm_repo):
1566.1.1 by Leo Zhang
Add assess_constraints
183
    """Test deploying charm with constraints."""
184
    client.deploy(charm, series=series, repository=charm_repo,
1587.1.19 by Andrew Beach
Got rid of the duplacate str member and pushed the Constraint to str converstions down to accomidate.
185
                  constraints=str(constraints))
1566.1.2 by Leo Zhang
Changes after review.
186
    client.wait_for_workloads()
1566.1.1 by Leo Zhang
Add assess_constraints
187
188
1587.1.10 by Andrew Beach
Added new code to support more asserts in assess_constraints. Mostly around juju_show_machine_hardware.
189
def deploy_charm_constraint(client, constraints, charm_name, charm_series,
190
                            charm_dir):
1587.1.3 by Andrew Beach
Moved the generic set up for deploy_constraints into a helper function.
191
    """Create a charm with constraints and test deploying it."""
1587.1.5 by Andrew Beach
Modified deploy_charm_constraint so it can be tested. Also added the approprate test.
192
    constraints_charm = Charm(charm_name,
193
                              'Test charm for constraints',
1587.1.8 by Andrew Beach
Fixed the test_instance_type_constraints plus 2 other one line fixes.
194
                              series=[charm_series])
1587.1.5 by Andrew Beach
Modified deploy_charm_constraint so it can be tested. Also added the approprate test.
195
    charm_root = constraints_charm.to_repo_dir(charm_dir)
196
    platform = 'ubuntu'
197
    charm = local_charm_path(charm=charm_name,
198
                             juju_ver=client.version,
199
                             series=charm_series,
200
                             repository=os.path.dirname(charm_root),
201
                             platform=platform)
1587.1.10 by Andrew Beach
Added new code to support more asserts in assess_constraints. Mostly around juju_show_machine_hardware.
202
    deploy_constraint(client, constraints, charm,
203
                      charm_series, charm_dir)
1566.1.1 by Leo Zhang
Add assess_constraints
204
205
1645 by Andrew Beach
Added show_machine to the client class. Updated and cleaned the hardware functions in assess_constraints.py.
206
def machine_hardware(client, machine):
207
    """Get hardware data about the given machine."""
208
    machine_data = client.show_machine(machine)
209
    hardware = machine_data['machines'][machine]['hardware']
1587.1.23 by Andrew Beach
Folded in my old changes and got an instance-type test running and passing.
210
    data = {}
211
    for kvp in hardware.split(' '):
212
        (key, value) = kvp.split('=')
213
        data[key] = value
214
    return data
215
216
1587.1.31 by Andrew Beach
Got the tests working for the latest Juju version.
217
def application_machines(client, application):
218
    """Get all the machines used to host the given application."""
1587.1.36 by Andrew Beach
Updated assess_constraints.application_machines to use get_status instead of get_juju_output.
219
    status = client.get_status()
220
    app_data = status.get_applications()[application]
1645.1.2 by Andrew Beach
Fix to test_show_machine and addition of assess_multiple_constraints.
221
    machines = [unit_data['machine'] for unit_data in
1751.1.12 by Aaron Bentley
Remove obsolete fakejuju output checker, emit status as bytes.
222
                app_data['units'].values()]
1587.1.36 by Andrew Beach
Updated assess_constraints.application_machines to use get_status instead of get_juju_output.
223
    return machines
1587.1.31 by Andrew Beach
Got the tests working for the latest Juju version.
224
225
1645 by Andrew Beach
Added show_machine to the client class. Updated and cleaned the hardware functions in assess_constraints.py.
226
def application_hardware(client, application):
227
    """Get hardware data about a machine for an application."""
228
    machines = application_machines(client, application)
229
    return machine_hardware(client, machines[0])
230
231
1587.1.28 by Andrew Beach
Added testing functions for root-disk, cores & cpu-power.
232
def prepare_constraint_test(client, constraints, charm_name,
1587.1.31 by Andrew Beach
Got the tests working for the latest Juju version.
233
                            charm_series='xenial'):
1587.1.28 by Andrew Beach
Added testing functions for root-disk, cores & cpu-power.
234
    """Deploy a charm with constraints and data to see if it meets them."""
235
    with temp_dir() as charm_dir:
236
        deploy_charm_constraint(client, constraints, charm_name,
237
                                charm_series, charm_dir)
238
        client.wait_for_started()
1645 by Andrew Beach
Added show_machine to the client class. Updated and cleaned the hardware functions in assess_constraints.py.
239
        return application_hardware(client, charm_name)
1587.1.28 by Andrew Beach
Added testing functions for root-disk, cores & cpu-power.
240
241
1587.1.3 by Andrew Beach
Moved the generic set up for deploy_constraints into a helper function.
242
def assess_virt_type(client, virt_type):
243
    """Assess the virt-type option for constraints"""
244
    if virt_type not in VIRT_TYPES:
245
        raise JujuAssertionError(virt_type)
1587.1.19 by Andrew Beach
Got rid of the duplacate str member and pushed the Constraint to str converstions down to accomidate.
246
    constraints = Constraints(virt_type=virt_type)
1587.1.35 by Andrew Beach
Replaced the string concatination with format calls.
247
    charm_name = 'virt-type-{}'.format(virt_type)
1587.1.3 by Andrew Beach
Moved the generic set up for deploy_constraints into a helper function.
248
    charm_series = 'xenial'
1587.1.5 by Andrew Beach
Modified deploy_charm_constraint so it can be tested. Also added the approprate test.
249
    with temp_dir() as charm_dir:
1587.1.10 by Andrew Beach
Added new code to support more asserts in assess_constraints. Mostly around juju_show_machine_hardware.
250
        deploy_charm_constraint(client, constraints, charm_name,
251
                                charm_series, charm_dir)
1587.1.3 by Andrew Beach
Moved the generic set up for deploy_constraints into a helper function.
252
253
1587.1.2 by Andrew Beach
Broke up assess_constraints so there is a sup function for testing each type of constraint, currently only one exits.
254
def assess_virt_type_constraints(client, test_kvm=False):
255
    """Assess deployment with virt-type constraints."""
1566.1.2 by Leo Zhang
Changes after review.
256
    if test_kvm:
257
        VIRT_TYPES.append("kvm")
1566.1.1 by Leo Zhang
Add assess_constraints
258
    for virt_type in VIRT_TYPES:
259
        assess_virt_type(client, virt_type)
260
    try:
261
        assess_virt_type(client, 'aws')
262
    except JujuAssertionError:
263
        log.info("Correctly rejected virt-type aws")
264
    else:
265
        raise JujuAssertionError("FAIL: Client deployed with virt-type aws")
1566.1.2 by Leo Zhang
Changes after review.
266
    if test_kvm:
267
        VIRT_TYPES.remove("kvm")
1566.1.1 by Leo Zhang
Add assess_constraints
268
1587.1.6 by Andrew Beach
Began adding new instance-type contraint testing code and the approprate unit tests.
269
1587.1.34 by Andrew Beach
Changed the error message used on a failure and added a more tests.
270
def get_failure_exception(client, constraints):
271
    """Create a JujuAssertionError with a detailed error message."""
272
    message = 'Test Failed: on {} with constraints "{}"'.format(
1674.1.3 by Aaron Bentley
Use provider rather than get_provider.
273
        client.env.provider, str(constraints))
1587.1.34 by Andrew Beach
Changed the error message used on a failure and added a more tests.
274
    return JujuAssertionError(message)
275
276
1587.1.37 by Andrew Beach
Added tools to create more generic constraints tests.
277
def assess_constraints_deploy(client, constraints, charm_name):
278
    """Check a single set of constraints on deploy.
279
280
    :param client: Client to deploy the charm to.
281
    :param constraints: Constraints used and checked against.
282
    :param charm_name: Name of the charm to try deploying.
283
    :raises JujuAssertionError if test fails."""
284
    data = prepare_constraint_test(client, constraints, charm_name)
285
    if not constraints.meets_all(data):
286
        raise get_failure_exception(client, constraints)
287
288
1587.1.6 by Andrew Beach
Began adding new instance-type contraint testing code and the approprate unit tests.
289
def assess_instance_type(client, provider, instance_type):
290
    """Assess the instance-type option for constraints"""
291
    if instance_type not in INSTANCE_TYPES[provider]:
292
        raise JujuAssertionError(instance_type)
1587.1.19 by Andrew Beach
Got rid of the duplacate str member and pushed the Constraint to str converstions down to accomidate.
293
    constraints = Constraints(instance_type=instance_type)
1587.1.35 by Andrew Beach
Replaced the string concatination with format calls.
294
    charm_name = 'instance-type-{}'.format(instance_type.replace('.', '-'))
1587.1.41 by Andrew Beach
Added assess_constraints_deploy_dict, which provides a cleaner interface for specifing tests. Added a test using it and removed some duplication.
295
    assess_constraints_deploy(client, constraints, charm_name)
1587.1.23 by Andrew Beach
Folded in my old changes and got an instance-type test running and passing.
296
297
298
def assess_instance_type_constraints(client, provider=None):
1587.1.6 by Andrew Beach
Began adding new instance-type contraint testing code and the approprate unit tests.
299
    """Assess deployment with instance-type constraints."""
1587.1.23 by Andrew Beach
Folded in my old changes and got an instance-type test running and passing.
300
    if provider is None:
1674.1.3 by Aaron Bentley
Use provider rather than get_provider.
301
        provider = client.env.provider
1587.1.6 by Andrew Beach
Began adding new instance-type contraint testing code and the approprate unit tests.
302
    if provider not in INSTANCE_TYPES:
1587.1.22 by Andrew Beach
Made testing a provider with no instance-types a no-op for assess_instance_type_constraints rather than an error.
303
        return
1587.1.6 by Andrew Beach
Began adding new instance-type contraint testing code and the approprate unit tests.
304
    for instance_type in INSTANCE_TYPES[provider]:
305
        assess_instance_type(client, provider, instance_type)
306
1566.1.1 by Leo Zhang
Add assess_constraints
307
1587.1.28 by Andrew Beach
Added testing functions for root-disk, cores & cpu-power.
308
def assess_root_disk_constraints(client, values):
309
    """Assess deployment with root-disk constraints."""
310
    for root_disk in values:
311
        constraints = Constraints(root_disk=root_disk)
1587.1.35 by Andrew Beach
Replaced the string concatination with format calls.
312
        charm_name = 'root-disk-{}'.format(root_disk.lower())
1587.1.41 by Andrew Beach
Added assess_constraints_deploy_dict, which provides a cleaner interface for specifing tests. Added a test using it and removed some duplication.
313
        assess_constraints_deploy(client, constraints, charm_name)
1587.1.28 by Andrew Beach
Added testing functions for root-disk, cores & cpu-power.
314
315
316
def assess_cores_constraints(client, values):
317
    """Assess deployment with cores constraints."""
318
    for cores in values:
319
        constraints = Constraints(cores=cores)
1587.1.35 by Andrew Beach
Replaced the string concatination with format calls.
320
        charm_name = 'cores-{}c'.format(cores)
1587.1.41 by Andrew Beach
Added assess_constraints_deploy_dict, which provides a cleaner interface for specifing tests. Added a test using it and removed some duplication.
321
        assess_constraints_deploy(client, constraints, charm_name)
1587.1.28 by Andrew Beach
Added testing functions for root-disk, cores & cpu-power.
322
323
324
def assess_cpu_power_constraints(client, values):
325
    """Assess deployment with cpu_power constraints."""
326
    for cpu_power in values:
327
        constraints = Constraints(cpu_power=cpu_power)
1587.1.35 by Andrew Beach
Replaced the string concatination with format calls.
328
        charm_name = 'cpu-power-{}cp'.format(cpu_power)
1587.1.41 by Andrew Beach
Added assess_constraints_deploy_dict, which provides a cleaner interface for specifing tests. Added a test using it and removed some duplication.
329
        assess_constraints_deploy(client, constraints, charm_name)
1587.1.28 by Andrew Beach
Added testing functions for root-disk, cores & cpu-power.
330
331
1645.1.2 by Andrew Beach
Fix to test_show_machine and addition of assess_multiple_constraints.
332
def assess_multiple_constraints(client, base_name, **kwargs):
333
    """Assess deployment with muliple_constraints.
334
335
    Makes sure the combination of constraints gives us new instance type."""
336
    finger_prints = []
337
    for (part, (constraint, value)) in enumerate(kwargs.iteritems()):
338
        data = prepare_constraint_test(
339
            client, Constraints(**{constraint: value}),
340
            '{}-part{}'.format(base_name, part))
341
        finger_prints.append(data)
342
    final_constraints = Constraints(**kwargs)
343
    data = prepare_constraint_test(client, final_constraints,
344
                                   '{}-whole'.format(base_name))
345
    if not final_constraints.meets_all(data):
346
        raise get_failure_exception(client, final_constraints)
347
    if data in finger_prints:
348
        raise JujuAssertionError(
349
            'Multiple Constraints did not change the hardware.')
350
351
1587.1.2 by Andrew Beach
Broke up assess_constraints so there is a sup function for testing each type of constraint, currently only one exits.
352
def assess_constraints(client, test_kvm=False):
353
    """Assess deployment with constraints."""
1674.1.3 by Aaron Bentley
Use provider rather than get_provider.
354
    provider = client.env.provider
1587.1.23 by Andrew Beach
Folded in my old changes and got an instance-type test running and passing.
355
    if 'lxd' == provider:
356
        assess_virt_type_constraints(client, test_kvm)
357
    elif 'ec2' == provider:
358
        assess_instance_type_constraints(client, provider)
1587.1.29 by Andrew Beach
Added the actual tests. They are not passing right now.
359
        assess_root_disk_constraints(client, ['16G'])
360
        assess_cores_constraints(client, ['2'])
361
        assess_cpu_power_constraints(client, ['30'])
1645.1.2 by Andrew Beach
Fix to test_show_machine and addition of assess_multiple_constraints.
362
        assess_multiple_constraints(client, 'root-disk-and-cpu-power',
363
                                    root_disk='15G', cpu_power='40')
1587.1.2 by Andrew Beach
Broke up assess_constraints so there is a sup function for testing each type of constraint, currently only one exits.
364
365
1566.1.1 by Leo Zhang
Add assess_constraints
366
def parse_args(argv):
367
    """Parse all arguments."""
368
    parser = argparse.ArgumentParser(description="Test constraints")
369
    add_basic_testing_arguments(parser)
370
    return parser.parse_args(argv)
371
372
373
def main(argv=None):
374
    args = parse_args(argv)
375
    configure_logging(args.verbose)
376
    bs_manager = BootstrapManager.from_args(args)
1566.1.2 by Leo Zhang
Changes after review.
377
    test_kvm = '--with-virttype-kvm' in args
1566.1.1 by Leo Zhang
Add assess_constraints
378
    with bs_manager.booted_context(args.upload_tools):
1587.1.15 by Andrew Beach
Merged constraints.py into [tests/test_]assess_constraints.py. Adding the approprate testing.
379
        assess_constraints(bs_manager.client, test_kvm)
1566.1.1 by Leo Zhang
Add assess_constraints
380
    return 0
381
382
383
if __name__ == '__main__':
384
    sys.exit(main())