47
47
self.id = max_id["id"] + 1
48
48
self.name = str(int(time.time()))
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"
57
return nonexistent_flavor
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
67
return nonexistent_flavor
69
def _existing_flavor(self):
70
"""return first instance type name"""
71
return instance_types.get_all_types().keys()[0]
50
73
def test_instance_type_create_then_delete(self):
51
74
"""Ensure instance types can be created"""
52
75
starting_inst_list = instance_types.get_all_types()
84
107
exception.InvalidInput,
85
108
instance_types.create, self.name, 256, 1, "aa", self.flavorid)
87
def test_non_existant_inst_type_shouldnt_delete(self):
110
def test_non_existent_inst_type_shouldnt_delete(self):
88
111
"""Ensures that instance type creation fails with invalid args"""
89
112
self.assertRaises(exception.ApiError,
90
instance_types.destroy, "sfsfsdfdfs")
113
instance_types.destroy,
114
self._nonexistent_flavor_name())
92
116
def test_repeated_inst_types_should_raise_api_error(self):
93
117
"""Ensures that instance duplicates raises ApiError"""
97
121
self.assertRaises(
98
122
exception.ApiError,
99
123
instance_types.create, new_name, 256, 1, 120, self.flavorid)
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())
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)
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())
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)
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))
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())
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())