Exemplo n.º 1
0
    def test_get_compute_nodes_flavor_no_extra_specs(self,
                                                     nova_client_mock):
        # setup fake nova api service list response
        compute_host_1 = fakes.FakeNovaServiceList(host='host-1')
        compute_host_2 = fakes.FakeNovaServiceList(host='host-2')
        compute_host_3 = fakes.FakeNovaServiceList(host='host-3')

        nova_client_mock.nova.services.list.return_value = [compute_host_1,
                                                            compute_host_2,
                                                            compute_host_3]

        # setup fake nova api flavor list response
        flavor_no_exta_specs = fakes.FakeNovaFlavorList(
            name='flavor_no_exta_specs')

        nova_client_mock.nova.flavors.list.return_value = [
            flavor_no_exta_specs]

        deployment = deploy.Deployment()
        deployment.flavor_name = 'flavor_no_exta_specs'
        deployment.openstack_client = nova_client_mock

        accommodation = {'compute_nodes': 3}
        expected = [{'host': 'host-1', 'zone': 'nova'},
                    {'host': 'host-2', 'zone': 'nova'},
                    {'host': 'host-3', 'zone': 'nova'}]

        observed = deployment._get_compute_nodes(accommodation)

        self.assertEqual(expected, observed)
Exemplo n.º 2
0
    def test_get_compute_nodes_flavor_extra_specs_with_match(
            self, nova_client_mock):
        # setup fake nova api service list response
        compute_host_1 = fakes.FakeNovaServiceList(host='host-1')
        compute_host_2 = fakes.FakeNovaServiceList(host='host-2')
        compute_host_3 = fakes.FakeNovaServiceList(host='host-3')

        nova_client_mock.nova.services.list.return_value = [
            compute_host_1, compute_host_2, compute_host_3
        ]

        # setup fake nova api flavor list response
        flavor_with_extra_specs = fakes.FakeNovaFlavorList(
            name='flavor_with_extra_specs',
            extra_specs={'aggregate_instance_extra_specs:special_hw': 'true'})

        nova_client_mock.nova.flavors.list.return_value = [
            flavor_with_extra_specs
        ]

        # setup fake nova api aggregate list response
        agg_host_1 = fakes.FakeNovaAggregateList(hosts=['host-1'])
        agg_host_2 = fakes.FakeNovaAggregateList(
            hosts=['host-2'], metadata={'special_hw': 'true'})
        agg_host_3 = fakes.FakeNovaAggregateList(hosts=['host-3'])

        nova_client_mock.nova.aggregates.list.return_value = [
            agg_host_1, agg_host_2, agg_host_3
        ]

        deployment = deploy.Deployment()
        deployment.flavor_name = 'flavor_with_extra_specs'
        deployment.openstack_client = nova_client_mock

        accommodation = {'compute_nodes': 3}
        expected = [{'host': 'host-2', 'zone': 'nova'}]

        observed = deployment._get_compute_nodes(accommodation)

        self.assertEqual(expected, observed)