コード例 #1
0
    def test_trusted_filter_combine_hosts(self, req_mock):
        fake_compute_nodes = [
            objects.ComputeNode(hypervisor_hostname='node1'),
            objects.ComputeNode(hypervisor_hostname='node2')
        ]
        with mock.patch('nova.objects.ComputeNodeList.get_all') as mocked:
            mocked.return_value = fake_compute_nodes
            self.filt_cls = trusted_filter.TrustedFilter()
        oat_data = {"hosts": [{"host_name": "node1",
                                    "trust_lvl": "untrusted",
                                    "vtime": "2012-09-09T05:10:40-04:00"}]}
        req_mock.return_value = requests.codes.OK, oat_data
        extra_specs = {'trust:trusted_host': 'trusted'}
        filter_properties = {'context': mock.sentinel.ctx,
                             'instance_type': {'memory_mb': 1024,
                                               'extra_specs': extra_specs}}
        host = fakes.FakeHostState('host1', 'node1', {})

        self.filt_cls.host_passes(host, filter_properties)  # Fill the caches
        self.assertTrue(req_mock.called)
        self.assertEqual(1, req_mock.call_count)
        call_args = list(req_mock.call_args[0])

        expected_call_args = ['POST', 'PollHosts', ['node2', 'node1']]
        self.assertJsonEqual(call_args, expected_call_args)
コード例 #2
0
    def test_trusted_filter_combine_hosts(self, req_mock):
        fake_compute_nodes = [
            {'hypervisor_hostname': 'node1',
             'service': {'host': 'host1'},
            },
            {'hypervisor_hostname': 'node2',
             'service': {'host': 'host2'},
            },
        ]
        with mock.patch('nova.db.compute_node_get_all') as mocked:
            mocked.return_value = fake_compute_nodes
            self.filt_cls = trusted_filter.TrustedFilter()
        oat_data = {"hosts": [{"host_name": "node1",
                                    "trust_lvl": "untrusted",
                                    "vtime": "2012-09-09T05:10:40-04:00"}]}
        req_mock.return_value = requests.codes.OK, oat_data
        extra_specs = {'trust:trusted_host': 'trusted'}
        filter_properties = {'context': mock.sentinel.ctx,
                             'instance_type': {'memory_mb': 1024,
                                               'extra_specs': extra_specs}}
        host = fakes.FakeHostState('host1', 'node1', {})

        self.filt_cls.host_passes(host, filter_properties)  # Fill the caches
        req_mock.assert_called_once_with("POST", "PollHosts",
                                         ["node1", "node2"])
コード例 #3
0
 def setUp(self):
     super(TestTrustedFilter, self).setUp()
     # TrustedFilter's constructor creates the attestation cache, which
     # calls to get a list of all the compute nodes.
     fake_compute_nodes = [
         objects.ComputeNode(hypervisor_hostname='node1'),
     ]
     with mock.patch('nova.objects.ComputeNodeList.get_all') as mocked:
         mocked.return_value = fake_compute_nodes
         self.filt_cls = trusted_filter.TrustedFilter()
コード例 #4
0
 def setUp(self):
     super(TestTrustedFilter, self).setUp()
     # TrustedFilter's constructor creates the attestation cache, which
     # calls to get a list of all the compute nodes.
     fake_compute_nodes = [
         {'hypervisor_hostname': 'node1',
          'service': {'host': 'host1'},
         }
     ]
     with mock.patch('nova.db.compute_node_get_all') as mocked:
         mocked.return_value = fake_compute_nodes
         self.filt_cls = trusted_filter.TrustedFilter()