220
221
self.assertIsNone(shell.remove(ip_address))
224
class Test_Omshell_nullify_lease(MAASTestCase):
225
"""Tests for Omshell.nullify_lease"""
227
def test__calls_omshell_correctly(self):
228
server_address = factory.make_string()
229
shared_key = factory.make_string()
230
ip_address = factory.make_ipv4_address()
231
shell = Omshell(server_address, shared_key)
233
# Instead of calling a real omshell, we'll just record the
234
# parameters passed to Popen.
235
run = self.patch(shell, '_run')
236
run.return_value = (0, '\nends = 00:00:00:00')
237
expected_script = dedent("""\
242
set ip-address = {ip}
244
set ends = 00:00:00:00
247
expected_script = expected_script.format(
248
server=server_address, key=shared_key, ip=ip_address)
249
shell.nullify_lease(ip_address)
250
self.assertThat(run, MockCalledOnceWith(expected_script))
252
def test__considers_nonexistent_lease_a_success(self):
253
server_address = factory.make_string()
254
shared_key = factory.make_string()
255
ip_address = factory.make_ipv4_address()
256
shell = Omshell(server_address, shared_key)
259
"obj: <null>\nobj: lease\nobj: lease\n"
260
"can't open object: not found\nobj: lease\n")
261
self.patch(shell, '_run').return_value = (0, output)
262
shell.nullify_lease(ip_address) # No exception.
263
self.assertThat(shell._run, MockCalledOnceWith(ANY))
265
def test__catches_invalid_error(self):
266
server_address = factory.make_string()
267
shared_key = factory.make_string()
268
ip_address = factory.make_ipv4_address()
269
shell = Omshell(server_address, shared_key)
271
output = "obj: <null>\nobj: lease\ninvalid value."
272
self.patch(shell, '_run').return_value = (0, output)
274
ExternalProcessError, shell.nullify_lease, ip_address)
276
def test__catches_failed_update(self):
277
server_address = factory.make_string()
278
shared_key = factory.make_string()
279
ip_address = factory.make_ipv4_address()
280
shell = Omshell(server_address, shared_key)
282
# make "ends" different to what we asked, so the post-run check
288
ip-address = 0a:00:00:72
292
hardware-address = 00:16:3e:06:45:5e
293
hardware-type = 00:00:00:01
302
self.patch(shell, '_run').return_value = (0, output)
304
ExternalProcessError, shell.nullify_lease, ip_address)
223
307
class Test_generate_omapi_key(MAASTestCase):
224
308
"""Tests for omshell.generate_omapi_key"""