Example #1
0
    def test_not_equal(self):
        # Setup
        overcloud_1 = models.Overcloud(name='foo')
        overcloud_2 = models.Overcloud(name='bar')

        # Test
        self.assertTrue(overcloud_1 != overcloud_2)
Example #2
0
    def test_post(self, mock_db_create, mock_process_stack,
                  mock_get_overcloud_roles):
        # Setup
        create_me = {'name': 'new'}

        fake_created = db_models.Overcloud(name='created')
        mock_db_create.return_value = fake_created
        mock_process_stack.return_value = {'stack': {'id': '1'}}
        mock_get_overcloud_roles.return_value = [
            mock.Mock(**{'id.return_value': 1, }),
            mock.Mock(**{'id.return_value': 2, })]

        # Test
        response = self.app.post_json(URL_OVERCLOUDS, params=create_me)
        result = response.json

        # Verify
        self.assertEqual(response.status_int, 201)
        self.assertEqual(result['name'], fake_created.name)

        self.assertEqual(1, mock_db_create.call_count)
        db_create_model = mock_db_create.call_args[0][0]
        self.assertTrue(isinstance(db_create_model,
                                   db_models.Overcloud))
        self.assertEqual(db_create_model.name, create_me['name'])
Example #3
0
    def test_from_db_model(self):
        # Setup
        db_attrs = [
            db_models.OvercloudAttribute(
                id=10,
                overcloud_id=1,
                key='key-1',
                value='value-1',
            ),
            db_models.OvercloudAttribute(
                id=20,
                overcloud_id=1,
                key='key-2',
                value='value-2',
            ),
        ]

        db_counts = [
            db_models.OvercloudRoleCount(
                id=100,
                overcloud_id=1,
                overcloud_role_id=5,
                num_nodes=5,
            )
        ]

        db_model = db_models.Overcloud(
            id=1,
            stack_id='stack-1',
            name='name-1',
            description='desc-1',
            attributes=db_attrs,
            counts=db_counts,
        )

        # Test
        api_model = api_models.Overcloud.from_db_model(db_model)

        # Verify
        self.assertTrue(api_model is not None)
        self.assertTrue(isinstance(api_model, api_models.Overcloud))

        self.assertEqual(api_model.id, db_model.id)
        self.assertEqual(api_model.stack_id, db_model.stack_id)
        self.assertEqual(api_model.name, db_model.name)
        self.assertEqual(api_model.description, db_model.description)

        self.assertEqual(len(api_model.attributes), len(db_model.attributes))
        self.assertTrue(isinstance(api_model.attributes, dict))
        for d_attr in db_model.attributes:
            self.assertEqual(api_model.attributes[d_attr.key], d_attr.value)

        self.assertEqual(len(api_model.counts), len(db_model.counts))
        for a_count, d_count in zip(api_model.counts, db_model.counts):
            self.assertTrue(isinstance(a_count, api_models.OvercloudRoleCount))
            self.assertEqual(a_count.id, d_count.id)
            self.assertEqual(a_count.overcloud_role_id,
                             d_count.overcloud_role_id)
            self.assertEqual(a_count.overcloud_id, d_count.overcloud_id)
            self.assertEqual(a_count.num_nodes, d_count.num_nodes)
Example #4
0
    def test_create_overcloud_duplicate_name(self):
        # Setup
        self.connection.create_overcloud(self.overcloud_1)
        duplicate = models.Overcloud(
            name=self.overcloud_1.name,
            description='irrelevant',
        )

        # Test
        self.assertRaises(exception.OvercloudExists,
                          self.connection.create_overcloud, duplicate)
Example #5
0
    def test_create_minimal_overcloud(self):
        # Setup
        overcloud = models.Overcloud(name='minimal')

        # Test
        saved = self.connection.create_overcloud(overcloud)

        # Verify
        self.assertEqual(saved.name, overcloud.name)
        self.assertEqual(saved.description, None)
        self.assertEqual(saved.attributes, [])
        self.assertEqual(saved.counts, [])
Example #6
0
    def setUp(self):
        super(OvercloudTests, self).setUp()

        self.connection = dbapi.Connection()

        self.role_1 = models.OvercloudRole(
            name='name-1',
            description='desc-1',
            image_name='image-1',
            flavor_id='tuvwxyz',
        )
        self.saved_role = self.connection.create_overcloud_role(self.role_1)

        self.attributes_1 = models.OvercloudAttribute(
            key='key-1',
            value='value-1',
        )

        self.attributes_2 = models.OvercloudAttribute(
            key='key-2',
            value='value-2',
        )

        self.count_1 = models.OvercloudRoleCount(
            overcloud_role_id=self.saved_role.id,
            num_nodes=4,
        )

        self.overcloud_1 = models.Overcloud(
            name='overcloud-1',
            description='desc-1',
            attributes=[self.attributes_1, self.attributes_2],
            counts=[self.count_1])

        self.overcloud_2 = models.Overcloud(name='overcloud-2',
                                            description='desc-2',
                                            attributes=[])
Example #7
0
    def test_put(self, mock_db_update, mock_process_stack):
        # Setup
        changes = {'name': 'updated'}

        overcloud_role_1 = db_models.OvercloudRole(
            image_name='overcloud-compute', flavor_id='1')

        overcloud_role_2 = db_models.OvercloudRole(
            image_name='overcloud-cinder-volume', flavor_id='1')

        overcloud_role_count_1 = db_models.OvercloudRoleCount(
            overcloud_role_id=1, num_nodes=5, overcloud_role=overcloud_role_1)

        overcloud_role_count_2 = db_models.OvercloudRoleCount(
            overcloud_role_id=2, num_nodes=9, overcloud_role=overcloud_role_2)

        attribute_1 = db_models.OvercloudAttribute(
            overcloud_id=1, key='name', value='updated')

        fake_updated = db_models.Overcloud(name='after-update',
                                           attributes=[attribute_1],
                                           counts=[overcloud_role_count_1,
                                                   overcloud_role_count_2])
        mock_db_update.return_value = fake_updated
        mock_process_stack.return_value = None

        # Test
        url = URL_OVERCLOUDS + '/' + '12345'
        response = self.app.put_json(url, params=changes)
        result = response.json

        # Verify
        self.assertEqual(response.status_int, 200)
        self.assertEqual(result['name'], fake_updated.name)

        self.assertEqual(1, mock_db_update.call_count)
        db_update_model = mock_db_update.call_args[0][0]
        self.assertTrue(isinstance(db_update_model,
                                   db_models.Overcloud))
        self.assertEqual(db_update_model.id, 12345)
        self.assertEqual(db_update_model.name, changes['name'])

        mock_process_stack.assert_called_once_with(
            {'name': 'updated'}, [overcloud_role_count_1,
                                  overcloud_role_count_2], {})
Example #8
0
    def test_get_one(self, mock_db_get):
        # Setup
        fake_attrs = [
            db_models.OvercloudAttribute(key='key1', value='value1'),
            db_models.OvercloudAttribute(key='password', value='secret'),
            db_models.OvercloudAttribute(key='AdminPassword', value='secret'),
        ]
        fake_result = db_models.Overcloud(name='foo', attributes=fake_attrs)
        mock_db_get.return_value = fake_result

        # Test
        url = URL_OVERCLOUDS + '/' + '12345'
        response = self.app.get(url)
        result = response.json

        # Verify
        self.assertEqual(response.status_int, 200)
        self.assertEqual(result['name'], 'foo')
        self.assertEqual(result['attributes']['key1'], 'value1')
        self.assertEqual(result['attributes']['password'], '******')
        self.assertEqual(result['attributes']['AdminPassword'], '******')

        mock_db_get.assert_called_once_with(12345)
Example #9
0
    def test_get_all(self, mock_db_get):
        # Setup
        fake_attrs = [
            db_models.OvercloudAttribute(key='key1', value='value1'),
            db_models.OvercloudAttribute(key='password', value='secret'),
            db_models.OvercloudAttribute(key='AdminPassword', value='secret'),
        ]
        fake_results = [db_models.Overcloud(name='foo', attributes=fake_attrs)]
        mock_db_get.return_value = fake_results

        # Test
        response = self.app.get(URL_OVERCLOUDS)
        result = response.json

        # Verify
        self.assertEqual(response.status_int, 200)
        self.assertTrue(isinstance(result, list))
        self.assertEqual(1, len(result))
        self.assertEqual(result[0]['name'], 'foo')
        self.assertEqual(result[0]['attributes']['key1'], 'value1')
        self.assertEqual(result[0]['attributes']['password'], '******')
        self.assertEqual(result[0]['attributes']['AdminPassword'], '******')

        mock_db_get.assert_called_once()
Example #10
0
 def test_update_nonexistent(self):
     fake = models.Overcloud(id='fake')
     self.assertRaises(exception.OvercloudNotFound,
                       self.connection.update_overcloud, fake)