~sseman/juju-ci-tools/model-change-watcher-py3-2

« back to all changes in this revision

Viewing changes to tests/test_substrate.py

  • Committer: Aaron Bentley
  • Date: 2016-11-28 22:04:46 UTC
  • mto: This revision was merged to the branch mainline in revision 1770.
  • Revision ID: aaron.bentley@canonical.com-20161128220446-8kqiz8h0ydxx0ms0
Extract has_nova_instance.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    get_config,
37
37
    get_job_instances,
38
38
    get_libvirt_domstate,
 
39
    has_nova_instance,
39
40
    JoyentAccount,
40
41
    LXDAccount,
41
42
    make_substrate_manager,
1509
1510
        self.assertFalse(rval)
1510
1511
 
1511
1512
 
 
1513
class TestHasNovaInstance(TestCase):
 
1514
 
 
1515
    def run_has_nova_instance(self, return_value=''):
 
1516
        boot_config = JujuData('foo', {
 
1517
            'type': 'openstack',
 
1518
            'region': 'lcy05',
 
1519
            'username': 'steve',
 
1520
            'password': 'password1',
 
1521
            'tenant-name': 'steven',
 
1522
            'auth-url': 'http://example.org',
 
1523
            }, 'home')
 
1524
        with patch('subprocess.check_output', autospec=True,
 
1525
                   return_value=return_value) as co_mock:
 
1526
            result = has_nova_instance(boot_config, 'i-255')
 
1527
        environ = dict(os.environ)
 
1528
        environ.update({
 
1529
            'OS_AUTH_URL': 'http://example.org',
 
1530
            'OS_USERNAME': 'steve',
 
1531
            'OS_PASSWORD': 'password1',
 
1532
            'OS_REGION_NAME': 'lcy05',
 
1533
            'OS_TENANT_NAME': 'steven',
 
1534
            })
 
1535
        co_mock.assert_called_once_with(['nova', 'list'], env=environ)
 
1536
        return result
 
1537
 
 
1538
    def test_has_nova_instance_false(self):
 
1539
        self.assertIs(False, self.run_has_nova_instance())
 
1540
 
 
1541
    def test_has_nova_instance_true(self):
 
1542
        self.assertIs(True, self.run_has_nova_instance('i-255'))
 
1543
 
 
1544
 
1512
1545
class EucaTestCase(TestCase):
1513
1546
 
1514
1547
    def test_get_job_instances_none(self):