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
=== modified file 'nova/tests/test_instance_types.py'
--- nova/tests/test_instance_types.py 2011-04-27 21:03:05 +0000
+++ nova/tests/test_instance_types.py 2011-08-24 23:05:28 +0000
@@ -47,6 +47,29 @@
47 self.id = max_id["id"] + 147 self.id = max_id["id"] + 1
48 self.name = str(int(time.time()))48 self.name = str(int(time.time()))
4949
50 def _nonexistent_flavor_name(self):
51 """return an instance type name not in the DB"""
52 nonexistent_flavor = "sdfsfsdf"
53 flavors = instance_types.get_all_types()
54 while nonexistent_flavor in flavors:
55 nonexistent_flavor += "z"
56 else:
57 return nonexistent_flavor
58
59 def _nonexistent_flavor_id(self):
60 """return an instance type ID not in the DB"""
61 nonexistent_flavor = 2700
62 flavor_ids = [value["id"] for key, value in\
63 instance_types.get_all_types().iteritems()]
64 while nonexistent_flavor in flavor_ids:
65 nonexistent_flavor += 1
66 else:
67 return nonexistent_flavor
68
69 def _existing_flavor(self):
70 """return first instance type name"""
71 return instance_types.get_all_types().keys()[0]
72
50 def test_instance_type_create_then_delete(self):73 def test_instance_type_create_then_delete(self):
51 """Ensure instance types can be created"""74 """Ensure instance types can be created"""
52 starting_inst_list = instance_types.get_all_types()75 starting_inst_list = instance_types.get_all_types()
@@ -84,10 +107,11 @@
84 exception.InvalidInput,107 exception.InvalidInput,
85 instance_types.create, self.name, 256, 1, "aa", self.flavorid)108 instance_types.create, self.name, 256, 1, "aa", self.flavorid)
86109
87 def test_non_existant_inst_type_shouldnt_delete(self):110 def test_non_existent_inst_type_shouldnt_delete(self):
88 """Ensures that instance type creation fails with invalid args"""111 """Ensures that instance type creation fails with invalid args"""
89 self.assertRaises(exception.ApiError,112 self.assertRaises(exception.ApiError,
90 instance_types.destroy, "sfsfsdfdfs")113 instance_types.destroy,
114 self._nonexistent_flavor_name())
91115
92 def test_repeated_inst_types_should_raise_api_error(self):116 def test_repeated_inst_types_should_raise_api_error(self):
93 """Ensures that instance duplicates raises ApiError"""117 """Ensures that instance duplicates raises ApiError"""
@@ -97,3 +121,43 @@
97 self.assertRaises(121 self.assertRaises(
98 exception.ApiError,122 exception.ApiError,
99 instance_types.create, new_name, 256, 1, 120, self.flavorid)123 instance_types.create, new_name, 256, 1, 120, self.flavorid)
124
125 def test_will_not_destroy_with_no_name(self):
126 """Ensure destroy sad path of no name raises error"""
127 self.assertRaises(exception.ApiError,
128 instance_types.destroy,
129 self._nonexistent_flavor_name())
130
131 def test_will_not_purge_without_name(self):
132 """Ensure purge without a name raises error"""
133 self.assertRaises(exception.InvalidInstanceType,
134 instance_types.purge, None)
135
136 def test_will_not_purge_with_wrong_name(self):
137 """Ensure purge without correct name raises error"""
138 self.assertRaises(exception.ApiError,
139 instance_types.purge,
140 self._nonexistent_flavor_name())
141
142 def test_will_not_get_bad_default_instance_type(self):
143 """ensures error raised on bad default instance type"""
144 FLAGS.default_instance_type = self._nonexistent_flavor_name()
145 self.assertRaises(exception.InstanceTypeNotFoundByName,
146 instance_types.get_default_instance_type)
147
148 def test_will_not_get_instance_type_by_name_with_no_name(self):
149 """Ensure get by name returns default flavor with no name"""
150 self.assertEqual(instance_types.get_default_instance_type(),
151 instance_types.get_instance_type_by_name(None))
152
153 def test_will_not_get_instance_type_with_bad_name(self):
154 """Ensure get by name returns default flavor with bad name"""
155 self.assertRaises(exception.InstanceTypeNotFound,
156 instance_types.get_instance_type,
157 self._nonexistent_flavor_name())
158
159 def test_will_not_get_flavor_by_bad_flavor_id(self):
160 """Ensure get by flavor raises error with wrong flavorid"""
161 self.assertRaises(exception.InstanceTypeNotFound,
162 instance_types.get_instance_type_by_name,
163 self._nonexistent_flavor_id())