def test_vsphere_no_validation(self): cloud = { 'type': 'vsphere', 'endpoint': '1.2.3.4', 'regions': { 'q': { 'endpoint': '1.2.3.4' } }, } spec = cloud_spec('foo', 'foo', cloud, exception=None) self.assertItemsEqual([ self.bogus_type, spec, xfail( cloud_spec('invalid-name-foo', 'invalid/name', cloud, exception=NameNotAccepted), 1641981, None), xfail( cloud_spec('long-name-foo', long_text, cloud, exception=None), 1641970, NameMismatch), xfail(make_long_endpoint(spec, endpoint_validation, regions=True), 1641970, CloudMismatch), ], iter_clouds({'foo': cloud}, basic_validation))
def test_manual(self): self.maxDiff = None cloud = {'type': 'manual', 'endpoint': 'http://example.com'} spec = cloud_spec('foo', 'foo', cloud) self.assertItemsEqual([ self.bogus_type, spec, xfail(cloud_spec('long-name-foo', long_text, cloud), 1641970, NameMismatch), xfail(cloud_spec('invalid-name-foo', 'invalid/name', cloud, exception=NameNotAccepted), 1641981, None), make_long_endpoint(spec, basic_validation) ], iter_clouds({'foo': cloud}, endpoint_validation))
def test_manual_no_validation(self): self.maxDiff = None cloud = {'type': 'manual', 'endpoint': 'http://example.com'} spec = cloud_spec('foo', 'foo', cloud) self.assertItemsEqual([ self.bogus_type, spec, xfail(cloud_spec('long-name-foo', long_text, cloud), 1641970, NameMismatch), xfail( cloud_spec('invalid-name-foo', 'invalid/name', cloud, exception=NameNotAccepted), 1641981, None), make_long_endpoint(spec, basic_validation) ], iter_clouds({'foo': cloud}, basic_validation))
def test_vsphere(self): cloud = { 'type': 'vsphere', 'endpoint': '1.2.3.4', 'regions': {'q': {'endpoint': '1.2.3.4'}}, } spec = cloud_spec('foo', 'foo', cloud, exception=None) self.assertItemsEqual([ self.bogus_type, spec, xfail(cloud_spec('invalid-name-foo', 'invalid/name', cloud, exception=NameNotAccepted), 1641981, None), xfail(cloud_spec('long-name-foo', long_text, cloud, exception=None), 1641970, NameMismatch), make_long_endpoint( spec, endpoint_validation, regions=True), ], iter_clouds({'foo': cloud}, endpoint_validation))
def test_assess_all_clouds(self): client = fake_juju_client(juju_home=self.juju_home) clouds = {'a': {'type': 'foo'}, 'b': {'type': 'bar'}} cloud_specs = iter_clouds(clouds, endpoint_validation) exception = Exception() with patch('assess_add_cloud.assess_cloud', side_effect=[TypeNotAccepted(), None] + [exception] * 7): with patch('sys.stdout'): with patch('logging.exception') as exception_mock: succeeded, xfail, failed = assess_all_clouds(client, cloud_specs) self.assertEqual({'bogus-type', 'a'}, succeeded) self.assertEqual({ 'b', 'bogus-auth-a', 'bogus-auth-b', 'invalid-name-a', 'invalid-name-b', 'long-name-a', 'long-name-b'}, failed) self.assertEqual(exception_mock.mock_calls, [call(exception)] * 7)
def test_assess_all_clouds(self): client = fake_juju_client(juju_home=self.juju_home) clouds = {'a': {'type': 'foo'}, 'b': {'type': 'bar'}} cloud_specs = iter_clouds(clouds, endpoint_validation) exception = Exception() with patch('assess_add_cloud.assess_cloud', side_effect=[TypeNotAccepted(), None] + [exception] * 7): with patch('sys.stdout'): with patch('logging.exception') as exception_mock: succeeded, xfail, failed = assess_all_clouds( client, cloud_specs) self.assertEqual({'bogus-type', 'a'}, succeeded) self.assertEqual( { 'b', 'bogus-auth-a', 'bogus-auth-b', 'invalid-name-a', 'invalid-name-b', 'long-name-a', 'long-name-b' }, failed) self.assertEqual(exception_mock.mock_calls, [call(exception)] * 7)
def test_openstack(self): config = {'type': 'openstack', 'endpoint': 'http://example.com', 'regions': {'bar': {'endpoint': 'http://baz.example.com'}}} spec = cloud_spec('foo', 'foo', config, exception=None) invalid_name = xfail( cloud_spec('invalid-name-foo', 'invalid/name', config, exception=NameNotAccepted), 1641981, None) long_name = xfail( cloud_spec('long-name-foo', long_text, config, exception=None), 1641970, NameMismatch) long_region = cloud_spec( 'long-endpoint-foo-bar', 'foo', deepcopy(config), InvalidEndpoint) long_region.config['regions']['bar']['endpoint'] = long_text bogus_auth = cloud_spec('bogus-auth-foo', 'foo', deepcopy(config), exception=AuthNotAccepted) bogus_auth.config['auth-types'] = ['asdf'] self.assertItemsEqual([ self.bogus_type, spec, invalid_name, long_name, long_region, bogus_auth, make_long_endpoint(spec, endpoint_validation), ], iter_clouds({'foo': config}, endpoint_validation))
def test_openstack_no_validation(self): config = { 'type': 'openstack', 'endpoint': 'http://example.com', 'regions': { 'bar': { 'endpoint': 'http://baz.example.com' } } } spec = cloud_spec('foo', 'foo', config, exception=None) invalid_name = xfail( cloud_spec('invalid-name-foo', 'invalid/name', config, exception=NameNotAccepted), 1641981, None) long_name = xfail( cloud_spec('long-name-foo', long_text, config, exception=None), 1641970, NameMismatch) long_region = xfail( cloud_spec('long-endpoint-foo-bar', 'foo', deepcopy(config), InvalidEndpoint), 1641970, CloudMismatch) long_region.config['regions']['bar']['endpoint'] = long_text bogus_auth = cloud_spec('bogus-auth-foo', 'foo', deepcopy(config), exception=AuthNotAccepted) bogus_auth.config['auth-types'] = ['asdf'] self.assertItemsEqual([ self.bogus_type, spec, invalid_name, long_name, long_region, bogus_auth, make_long_endpoint(spec, basic_validation), ], iter_clouds({'foo': config}, basic_validation))