summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-05-09 15:20:39 +0000
committerGerrit Code Review <review@openstack.org>2013-05-09 15:20:39 +0000
commit623ab8ab66df1a950f3a2af71e30699c1380b4f2 (patch)
tree75cf443d44c7bf8194ba0139637e51a5e8051d69
parent33b966771b672996a7b0d9608f1f7b8684cc459f (diff)
parentaeef5c3f1917969fc2dc524346784b197729a9e9 (diff)
downloadnova-623ab8ab66df1a950f3a2af71e30699c1380b4f2.tar.gz
nova-623ab8ab66df1a950f3a2af71e30699c1380b4f2.tar.xz
nova-623ab8ab66df1a950f3a2af71e30699c1380b4f2.zip
Merge "Fix variable referenced before assginment in vmwareapi code."
-rw-r--r--nova/tests/test_vmwareapi_vm_util.py55
-rw-r--r--nova/virt/vmwareapi/vm_util.py5
2 files changed, 56 insertions, 4 deletions
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")
diff --git a/nova/virt/vmwareapi/vm_util.py b/nova/virt/vmwareapi/vm_util.py
index 9fb8e9bd5..4287b4eaa 100644
--- a/nova/virt/vmwareapi/vm_util.py
+++ b/nova/virt/vmwareapi/vm_util.py
@@ -553,7 +553,6 @@ def get_datastore_ref_and_name(session, cluster=None, host=None):
"Datastore", data_store_mors,
["summary.type", "summary.name",
"summary.capacity", "summary.freeSpace"])
-
for elem in data_stores:
ds_name = None
ds_type = None
@@ -570,8 +569,6 @@ def get_datastore_ref_and_name(session, cluster=None, host=None):
ds_free = prop.val
# Local storage identifier
if ds_type == "VMFS" or ds_type == "NFS":
- data_store_name = ds_name
- return elem.obj, data_store_name, ds_cap, ds_free
+ return elem.obj, ds_name, ds_cap, ds_free
- if data_store_name is None:
raise exception.DatastoreNotFound()