~julian-edwards/maas/1.2-say-bug-1172966

« back to all changes in this revision

Viewing changes to src/provisioningserver/tests/test_cobblersession.py

  • Committer: Tarmac
  • Author(s): Gavin Panella
  • Date: 2012-03-12 17:30:50 UTC
  • mfrom: (246.5.16 cobbler-edit-before-add)
  • Revision ID: ed@carob-20120312173050-p8vk84wvegbvzjke
[r=rvb][bug=][author=allenap] Never clobbler Cobbler; edit before add instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from provisioningserver import cobblerclient
19
19
from provisioningserver.testing.fakecobbler import (
20
20
    fake_auth_failure_string,
 
21
    fake_object_not_found_string,
21
22
    fake_token,
22
23
    )
23
24
from testtools.content import text_content
254
255
        self.assertTrue(
255
256
            cobblerclient.looks_like_auth_expiry(make_auth_failure()))
256
257
 
 
258
    def test_looks_like_object_not_found_for_regular_exception(self):
 
259
        self.assertFalse(
 
260
            cobblerclient.looks_like_object_not_found(RuntimeError("Error")))
 
261
 
 
262
    def test_looks_like_object_not_found_for_other_Fault(self):
 
263
        self.assertFalse(
 
264
            cobblerclient.looks_like_object_not_found(
 
265
                Fault(1, "Missing sprocket")))
 
266
 
 
267
    def test_looks_like_object_not_found_recognizes_object_not_found(self):
 
268
        error = Fault(1, fake_object_not_found_string("distro", "bob"))
 
269
        self.assertTrue(
 
270
            cobblerclient.looks_like_object_not_found(error))
 
271
 
257
272
    @inlineCallbacks
258
273
    def test_call_reauthenticates_and_retries_on_auth_failure(self):
259
274
        # If a call triggers an authentication error, call()
416
431
                session, 'incomplete_system', {})
417
432
 
418
433
    @inlineCallbacks
 
434
    def test_new_attempts_edit_before_creating_new(self):
 
435
        # CobblerObject.new always attempts an extended edit operation on the
 
436
        # given object first, following by an add should the object not yet
 
437
        # exist.
 
438
        session = make_recording_session()
 
439
        not_found_string = fake_object_not_found_string("system", "carcass")
 
440
        not_found = Fault(1, not_found_string)
 
441
        session.proxy.set_return_values([not_found, True])
 
442
        yield cobblerclient.CobblerSystem.new(
 
443
            session, "carcass", {"profile": "heartwork"})
 
444
        expected_calls = [
 
445
            # First an edit is attempted...
 
446
            ("xapi_object_edit", "system", "carcass", "edit",
 
447
             {"name": "carcass", "profile": "heartwork"},
 
448
             session.token),
 
449
            # Followed by an add.
 
450
            ("xapi_object_edit", "system", "carcass", "add",
 
451
             {"name": "carcass", "profile": "heartwork"},
 
452
             session.token),
 
453
            ]
 
454
        self.assertEqual(expected_calls, session.proxy.calls)
 
455
 
 
456
    @inlineCallbacks
419
457
    def test_modify(self):
420
458
        session = make_recording_session()
421
459
        session.proxy.set_return_values([True])
447
485
        # Fake that Cobbler holds the following attributes about the distro
448
486
        # just created.
449
487
        values_stored = {
450
 
            "clobber": True,
451
488
            "initrd": "an_initrd",
452
489
            "kernel": "a_kernel",
453
490
            "likes": "cabbage",
472
509
        # Fake that Cobbler holds the following attributes about the distros
473
510
        # just created.
474
511
        values_stored = [
475
 
            {"clobber": True,
476
 
             "initrd": "an_initrd",
 
512
            {"initrd": "an_initrd",
477
513
             "kernel": "a_kernel",
478
514
             "likes": "cabbage",
479
515
             "name": "alice"},