Merge lp:~ken-pepple/nova/lp828596 into lp:~hudson-openstack/nova/trunk

Proposed by Ken Pepple
Status: Merged
Approved by: Ed Leafe
Approved revision: 1468
Merged at revision: 1495
Proposed branch: lp:~ken-pepple/nova/lp828596
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 91 lines (+66/-2)
1 file modified
nova/tests/test_instance_types.py (+66/-2)
To merge this branch: bzr merge lp:~ken-pepple/nova/lp828596
Reviewer Review Type Date Requested Status
Ed Leafe (community) Approve
Mandell (community) community Needs Fixing
Alex Meade (community) Approve
Brian Waldon (community) Approve
Jay Pipes (community) Approve
Soren Hansen Pending
Review via email: mp+72310@code.launchpad.net

Description of the change

added unit tests to instance_types for rainy day paths

To post a comment you must log in.
Revision history for this message
Jay Pipes (jaypipes) wrote :

rock on. nice work, Ken! :)

review: Approve
Revision history for this message
Brian Waldon (bcwaldon) wrote :

Looks good, Ken.

review: Approve
Revision history for this message
Alex Meade (alex-meade) :
review: Approve
Revision history for this message
Ed Leafe (ed-leafe) wrote :

Line 13: Are you trying to append the letter 'z' to the nonexistant_flavor value? If so, that is not the correct syntax. The statement:
    nonexistant_flavor.join("z")
will *always* return the letter "z" by itself.

Perhaps you meant:
    nonexistant_flavor = "%s%s" % (nonexistant_flavor, "z")

Oh, and it should be spelled 'nonexistent' :)

review: Needs Fixing
Revision history for this message
Mandell (mdegerne) wrote :

Agree with Ed, except that you could also do:
     nonexistant_flavor = nonexistant_flavor.join(["z","z"])

I really don't know which is more efficient in python.

review: Needs Fixing (community)
Revision history for this message
Ken Pepple (ken-pepple) wrote :

> Line 13: Are you trying to append the letter 'z' to the nonexistant_flavor
> value? If so, that is not the correct syntax. The statement:
> nonexistant_flavor.join("z")
> will *always* return the letter "z" by itself.

woof. i mixed ruby in python. fixed.

Revision history for this message
Ken Pepple (ken-pepple) wrote :

> Agree with Ed, except that you could also do:
> nonexistant_flavor = nonexistant_flavor.join(["z","z"])
>
> I really don't know which is more efficient in python.

i went with the x += "z" syntax ... not sure if this will ever get exercised as the instance_flavors are set at migration time.

Revision history for this message
Ed Leafe (ed-leafe) wrote :

Ken, looks good, and I feel *really* petty for bringing this up, but...

Can you fix the spelling of the method name "test_non_existant_inst_type_shouldnt_delete"? I promise I'll approve once that's changed. :)

Revision history for this message
Ken Pepple (ken-pepple) wrote :

> Ken, looks good, and I feel *really* petty for bringing this up, but...
>
> Can you fix the spelling of the method name
> "test_non_existant_inst_type_shouldnt_delete"? I promise I'll approve once
> that's changed. :)

fair enough. but for the record, I prefer the french spelling - http://www.online-dictionary.biz/french/english/meaning/existant

Revision history for this message
Ed Leafe (ed-leafe) wrote :

Kissing up to Thierry, eh? ;-)

And apologies for the nit-pickiness. I blame the nuns who beat that stuff into me.

review: Approve
Revision history for this message
Ed Leafe (ed-leafe) wrote :

Since Mandell's objections were the same as mine, and they have been properly addressed, I'm going to override his 'Needs Fixing' and mark this as approved.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/tests/test_instance_types.py'
2--- nova/tests/test_instance_types.py 2011-04-27 21:03:05 +0000
3+++ nova/tests/test_instance_types.py 2011-08-24 23:05:28 +0000
4@@ -47,6 +47,29 @@
5 self.id = max_id["id"] + 1
6 self.name = str(int(time.time()))
7
8+ def _nonexistent_flavor_name(self):
9+ """return an instance type name not in the DB"""
10+ nonexistent_flavor = "sdfsfsdf"
11+ flavors = instance_types.get_all_types()
12+ while nonexistent_flavor in flavors:
13+ nonexistent_flavor += "z"
14+ else:
15+ return nonexistent_flavor
16+
17+ def _nonexistent_flavor_id(self):
18+ """return an instance type ID not in the DB"""
19+ nonexistent_flavor = 2700
20+ flavor_ids = [value["id"] for key, value in\
21+ instance_types.get_all_types().iteritems()]
22+ while nonexistent_flavor in flavor_ids:
23+ nonexistent_flavor += 1
24+ else:
25+ return nonexistent_flavor
26+
27+ def _existing_flavor(self):
28+ """return first instance type name"""
29+ return instance_types.get_all_types().keys()[0]
30+
31 def test_instance_type_create_then_delete(self):
32 """Ensure instance types can be created"""
33 starting_inst_list = instance_types.get_all_types()
34@@ -84,10 +107,11 @@
35 exception.InvalidInput,
36 instance_types.create, self.name, 256, 1, "aa", self.flavorid)
37
38- def test_non_existant_inst_type_shouldnt_delete(self):
39+ def test_non_existent_inst_type_shouldnt_delete(self):
40 """Ensures that instance type creation fails with invalid args"""
41 self.assertRaises(exception.ApiError,
42- instance_types.destroy, "sfsfsdfdfs")
43+ instance_types.destroy,
44+ self._nonexistent_flavor_name())
45
46 def test_repeated_inst_types_should_raise_api_error(self):
47 """Ensures that instance duplicates raises ApiError"""
48@@ -97,3 +121,43 @@
49 self.assertRaises(
50 exception.ApiError,
51 instance_types.create, new_name, 256, 1, 120, self.flavorid)
52+
53+ def test_will_not_destroy_with_no_name(self):
54+ """Ensure destroy sad path of no name raises error"""
55+ self.assertRaises(exception.ApiError,
56+ instance_types.destroy,
57+ self._nonexistent_flavor_name())
58+
59+ def test_will_not_purge_without_name(self):
60+ """Ensure purge without a name raises error"""
61+ self.assertRaises(exception.InvalidInstanceType,
62+ instance_types.purge, None)
63+
64+ def test_will_not_purge_with_wrong_name(self):
65+ """Ensure purge without correct name raises error"""
66+ self.assertRaises(exception.ApiError,
67+ instance_types.purge,
68+ self._nonexistent_flavor_name())
69+
70+ def test_will_not_get_bad_default_instance_type(self):
71+ """ensures error raised on bad default instance type"""
72+ FLAGS.default_instance_type = self._nonexistent_flavor_name()
73+ self.assertRaises(exception.InstanceTypeNotFoundByName,
74+ instance_types.get_default_instance_type)
75+
76+ def test_will_not_get_instance_type_by_name_with_no_name(self):
77+ """Ensure get by name returns default flavor with no name"""
78+ self.assertEqual(instance_types.get_default_instance_type(),
79+ instance_types.get_instance_type_by_name(None))
80+
81+ def test_will_not_get_instance_type_with_bad_name(self):
82+ """Ensure get by name returns default flavor with bad name"""
83+ self.assertRaises(exception.InstanceTypeNotFound,
84+ instance_types.get_instance_type,
85+ self._nonexistent_flavor_name())
86+
87+ def test_will_not_get_flavor_by_bad_flavor_id(self):
88+ """Ensure get by flavor raises error with wrong flavorid"""
89+ self.assertRaises(exception.InstanceTypeNotFound,
90+ instance_types.get_instance_type_by_name,
91+ self._nonexistent_flavor_id())