From aeef5c3f1917969fc2dc524346784b197729a9e9 Mon Sep 17 00:00:00 2001 From: Yaguang Tang Date: Wed, 8 May 2013 16:08:05 +0800 Subject: Fix variable referenced before assginment in vmwareapi code. Add unitests for VMwareapi vm_util. fix bug #1177689 Change-Id: If16109ee626c197227affba122c2e4986d92d2df --- nova/tests/test_vmwareapi_vm_util.py | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 nova/tests/test_vmwareapi_vm_util.py (limited to 'nova/tests') diff --git a/nova/tests/test_vmwareapi_vm_util.py b/nova/tests/test_vmwareapi_vm_util.py new file mode 100644 index 000000000..eda2c25f9 --- /dev/null +++ b/nova/tests/test_vmwareapi_vm_util.py @@ -0,0 +1,55 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# Copyright 2013 Canonical Corp. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from nova import exception +from nova import test +from nova.virt.vmwareapi import fake +from nova.virt.vmwareapi import vm_util + + +class fake_session(object): + def __init__(self, ret=None): + self.ret = ret + + def _call_method(self, *args): + return self.ret + + +class VMwareVMUtilTestCase(test.TestCase): + def setUp(self): + super(VMwareVMUtilTestCase, self).setUp() + + def tearDown(self): + super(VMwareVMUtilTestCase, self).tearDown() + + def test_get_datastore_ref_and_name(self): + result = vm_util.get_datastore_ref_and_name( + fake_session([fake.Datastore()])) + + self.assertEquals(result[1], "fake-ds") + self.assertEquals(result[2], 1024 * 1024 * 1024) + self.assertEquals(result[3], 1024 * 1024 * 500) + + def test_get_datastore_ref_and_name_without_datastore(self): + + self.assertRaises(exception.DatastoreNotFound, + vm_util.get_datastore_ref_and_name, + fake_session(), host="fake-host") + + self.assertRaises(exception.DatastoreNotFound, + vm_util.get_datastore_ref_and_name, + fake_session(), cluster="fake-cluster") -- cgit