Exemplo n.º 1
0
 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))
Exemplo n.º 2
0
 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))
Exemplo n.º 3
0
 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))
Exemplo n.º 4
0
 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))
Exemplo n.º 5
0
def make_long_endpoint(spec, validation, regions=False):
    config = deepcopy(spec.config)
    config['endpoint'] = long_text
    if regions:
        for region in config['regions'].values():
            region['endpoint'] = long_text
    spec = cloud_spec('long-endpoint-{}'.format(spec.name), spec.name, config,
                      InvalidEndpoint)
    if validation.is_basic:
        spec = xfail(spec, 1641970, CloudMismatch)
    return spec
Exemplo n.º 6
0
def make_long_endpoint(spec, validation, regions=False):
    config = deepcopy(spec.config)
    config['endpoint'] = long_text
    if regions:
        for region in config['regions'].values():
            region['endpoint'] = long_text
    spec = cloud_spec('long-endpoint-{}'.format(spec.name), spec.name, config,
                      InvalidEndpoint)
    if validation.is_basic:
        spec = xfail(spec, 1641970, CloudMismatch)
    return spec
Exemplo n.º 7
0
 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))
Exemplo n.º 8
0
 def test_xfail(self):
     cloud_specs = [xfail(cloud_spec('label1', 'name1', {'config': '1'}),
                          27, TypeNotAccepted)]
     client = fake_juju_client(juju_home=self.juju_home)
     with patch('assess_add_cloud.assess_cloud',
                side_effect=TypeNotAccepted):
         with patch('logging.exception') as exception_mock:
             with patch('sys.stdout'):
                 succeeded, xfailed, failed = assess_all_clouds(client,
                                                                cloud_specs)
     self.assertEqual(set(), failed)
     self.assertEqual({27: {'label1'}}, xfailed)
     self.assertEqual(0, exception_mock.call_count)
Exemplo n.º 9
0
 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))
Exemplo n.º 10
0
 def test_xfail(self):
     cloud_specs = [
         xfail(cloud_spec('label1', 'name1', {'config': '1'}), 27,
               TypeNotAccepted)
     ]
     client = fake_juju_client(juju_home=self.juju_home)
     with patch('assess_add_cloud.assess_cloud',
                side_effect=TypeNotAccepted):
         with patch('logging.exception') as exception_mock:
             with patch('sys.stdout'):
                 succeeded, xfailed, failed = assess_all_clouds(
                     client, cloud_specs)
     self.assertEqual(set(), failed)
     self.assertEqual({27: {'label1'}}, xfailed)
     self.assertEqual(0, exception_mock.call_count)
Exemplo n.º 11
0
 def test_failed_notraised(self):
     client = fake_juju_client(juju_home=self.juju_home)
     cloud_specs = [
         cloud_spec('label', 'name', {'config': '1'}, TypeNotAccepted)]
     with patch('assess_add_cloud.assess_cloud'):
         with patch('logging.exception') as exception_mock:
             with patch('sys.stdout'):
                 succeeded, xfailed, failed = assess_all_clouds(client,
                                                                cloud_specs)
     self.assertEqual(set(['label']), failed)
     self.assertEqual(1, exception_mock.call_count)
     raised_e = exception_mock.mock_calls[0][1][0]
     self.assertEqual(
         "Expected exception not raised: "
         "<class 'jujupy.client.TypeNotAccepted'>",
         raised_e.message)
Exemplo n.º 12
0
 def test_failed_notraised(self):
     client = fake_juju_client(juju_home=self.juju_home)
     cloud_specs = [
         cloud_spec('label', 'name', {'config': '1'}, TypeNotAccepted)
     ]
     with patch('assess_add_cloud.assess_cloud'):
         with patch('logging.exception') as exception_mock:
             with patch('sys.stdout'):
                 succeeded, xfailed, failed = assess_all_clouds(
                     client, cloud_specs)
     self.assertEqual(set(['label']), failed)
     self.assertEqual(1, exception_mock.call_count)
     raised_e = exception_mock.mock_calls[0][1][0]
     self.assertEqual(
         "Expected exception not raised: "
         "<class 'jujupy.client.TypeNotAccepted'>", raised_e.message)
Exemplo n.º 13
0
 def test_cloud_spec(self):
     self.assertEqual(
         CloudSpec('label1', 'name1', {'config': '1'}, None, None),
         cloud_spec('label1', 'name1', {'config': '1'}))
Exemplo n.º 14
0
 def test_cloud_spec(self):
     self.assertEqual(
         CloudSpec('label1', 'name1', {'config': '1'}, None, None),
         cloud_spec('label1', 'name1', {'config': '1'}))
Exemplo n.º 15
0
class TestIterClouds(FakeHomeTestCase):

    bogus_type = cloud_spec('bogus-type',
                            'bogus-type', {'type': 'bogus'},
                            exception=TypeNotAccepted)

    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_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_maas(self):
        cloud = {
            'type': 'maas',
            'endpoint': 'http://example.com',
        }
        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),
        ], iter_clouds({'foo': cloud}, endpoint_validation))

    def test_maas_no_validation(self):
        cloud = {
            'type': 'maas',
            'endpoint': 'http://example.com',
        }
        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, basic_validation),
        ], iter_clouds({'foo': cloud}, basic_validation))

    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))