diff options
-rw-r--r-- | nova/api/openstack/compute/contrib/simple_tenant_usage.py | 7 | ||||
-rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py | 15 | ||||
-rw-r--r-- | nova/tests/compute/test_compute.py | 1 | ||||
-rw-r--r-- | nova/tests/test_libvirt.py | 8 | ||||
-rw-r--r-- | nova/tests/virt/disk/test_nbd.py | 2 | ||||
-rwxr-xr-x | nova/virt/libvirt/driver.py | 32 | ||||
-rwxr-xr-x | run_tests.sh | 2 |
7 files changed, 40 insertions, 27 deletions
diff --git a/nova/api/openstack/compute/contrib/simple_tenant_usage.py b/nova/api/openstack/compute/contrib/simple_tenant_usage.py index 2313c00ac..f219689f7 100644 --- a/nova/api/openstack/compute/contrib/simple_tenant_usage.py +++ b/nova/api/openstack/compute/contrib/simple_tenant_usage.py @@ -18,6 +18,8 @@ import datetime import urlparse +from webob import exc + from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil @@ -204,6 +206,11 @@ class SimpleTenantUsageController(object): period_start = self._parse_datetime(env.get('start', [None])[0]) period_stop = self._parse_datetime(env.get('end', [None])[0]) + if not period_start < period_stop: + msg = _("Invalid start time. The start time cannot occur after " + "the end time.") + raise exc.HTTPBadRequest(explanation=msg) + detailed = env.get('detailed', ['0'])[0] == '1' return (period_start, period_stop, detailed) diff --git a/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py b/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py index 440c97fbd..ef4aacae8 100644 --- a/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py +++ b/nova/tests/api/openstack/compute/contrib/test_simple_tenant_usage.py @@ -218,6 +218,21 @@ class SimpleTenantUsageTest(test.TestCase): finally: policy.reset() + def test_get_tenants_usage_with_bad_start_date(self): + future = NOW + datetime.timedelta(hours=HOURS) + tenant_id = 0 + req = webob.Request.blank( + '/v2/faketenant_0/os-simple-tenant-usage/' + 'faketenant_%s?start=%s&end=%s' % + (tenant_id, future.isoformat(), NOW.isoformat())) + req.method = "GET" + req.headers["content-type"] = "application/json" + + res = req.get_response(fakes.wsgi_app( + fake_auth_context=self.user_context, + init_only=('os-simple-tenant-usage',))) + self.assertEqual(res.status_int, 400) + class SimpleTenantUsageSerializerTest(test.TestCase): def _verify_server_usage(self, raw_usage, tree): diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py index 2e8c07f18..6c58fffe0 100644 --- a/nova/tests/compute/test_compute.py +++ b/nova/tests/compute/test_compute.py @@ -1792,7 +1792,6 @@ class ComputeTestCase(BaseTestCase): kwargs = {} instance = self._create_fake_instance() - self.compute.run_instance(self.context, instance=instance) # The API would have set task_state, so do that here to test # that the state gets reverted on failure diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index c93bb0168..d2cd5a757 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -3393,13 +3393,7 @@ class HostStateTestCase(test.TestCase): return HostStateTestCase.instance_caps def test_update_status(self): - virtapi = fake.FakeVirtAPI() - self.mox.StubOutWithMock(libvirt_driver, 'LibvirtDriver') - libvirt_driver.LibvirtDriver(virtapi, True).AndReturn( - self.FakeConnection()) - - self.mox.ReplayAll() - hs = libvirt_driver.HostState(virtapi, True) + hs = libvirt_driver.HostState(self.FakeConnection()) stats = hs._stats self.assertEquals(stats["vcpus"], 1) self.assertEquals(stats["vcpus_used"], 0) diff --git a/nova/tests/virt/disk/test_nbd.py b/nova/tests/virt/disk/test_nbd.py index 59b0784d9..750506882 100644 --- a/nova/tests/virt/disk/test_nbd.py +++ b/nova/tests/virt/disk/test_nbd.py @@ -141,6 +141,8 @@ class NbdTestCase(test.TestCase): def test_inner_get_dev_no_devices(self): tempdir = self.useFixture(fixtures.TempDir()).path + self.stubs.Set(nbd.NbdMount, '_detect_nbd_devices', + _fake_detect_nbd_devices_none) n = nbd.NbdMount(None, tempdir) self.assertFalse(n._inner_get_dev()) diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 4e2fb9d39..386fe836c 100755 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -319,7 +319,7 @@ class LibvirtDriver(driver.ComputeDriver): @property def host_state(self): if not self._host_state: - self._host_state = HostState(self.virtapi, self.read_only) + self._host_state = HostState(self) return self._host_state def has_min_version(self, lv_ver=None, hv_ver=None, hv_type=None): @@ -3306,12 +3306,10 @@ class LibvirtDriver(driver.ComputeDriver): class HostState(object): """Manages information about the compute node through libvirt.""" - def __init__(self, virtapi, read_only): + def __init__(self, driver): super(HostState, self).__init__() - self.read_only = read_only self._stats = {} - self.connection = None - self.virtapi = virtapi + self.driver = driver self.update_status() def get_host_stats(self, refresh=False): @@ -3325,23 +3323,21 @@ class HostState(object): def update_status(self): """Retrieve status info from libvirt.""" LOG.debug(_("Updating host stats")) - if self.connection is None: - self.connection = LibvirtDriver(self.virtapi, self.read_only) data = {} - data["vcpus"] = self.connection.get_vcpu_total() - data["vcpus_used"] = self.connection.get_vcpu_used() - data["cpu_info"] = jsonutils.loads(self.connection.get_cpu_info()) - data["disk_total"] = self.connection.get_local_gb_total() - data["disk_used"] = self.connection.get_local_gb_used() + data["vcpus"] = self.driver.get_vcpu_total() + data["vcpus_used"] = self.driver.get_vcpu_used() + data["cpu_info"] = jsonutils.loads(self.driver.get_cpu_info()) + data["disk_total"] = self.driver.get_local_gb_total() + data["disk_used"] = self.driver.get_local_gb_used() data["disk_available"] = data["disk_total"] - data["disk_used"] - data["host_memory_total"] = self.connection.get_memory_mb_total() + data["host_memory_total"] = self.driver.get_memory_mb_total() data["host_memory_free"] = (data["host_memory_total"] - - self.connection.get_memory_mb_used()) - data["hypervisor_type"] = self.connection.get_hypervisor_type() - data["hypervisor_version"] = self.connection.get_hypervisor_version() - data["hypervisor_hostname"] = self.connection.get_hypervisor_hostname() + self.driver.get_memory_mb_used()) + data["hypervisor_type"] = self.driver.get_hypervisor_type() + data["hypervisor_version"] = self.driver.get_hypervisor_version() + data["hypervisor_hostname"] = self.driver.get_hypervisor_hostname() data["supported_instances"] = \ - self.connection.get_instance_capabilities() + self.driver.get_instance_capabilities() self._stats = data diff --git a/run_tests.sh b/run_tests.sh index 5a76b514f..9872858b4 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -149,7 +149,7 @@ function copy_subunit_log { function run_pep8 { echo "Running PEP8 and HACKING compliance check..." - bash tools/run_pep8.sh + bash -c "${wrapper} tools/run_pep8.sh" } |