def test_always_logout_iscsi(self):
        """logout_iscsi() must be called once login_iscsi() is called."""
        address = '127.0.0.1'
        port = 3306
        iqn = 'iqn.xyz'
        lun = 1
        image_path = '/tmp/xyz/image'
        pxe_config_path = '/tmp/abc/pxeconfig'
        root_mb = 128
        swap_mb = 64

        dev = '/dev/fake'

        self.mox.StubOutWithMock(bmdh, 'get_dev')
        self.mox.StubOutWithMock(bmdh, 'get_image_mb')
        self.mox.StubOutWithMock(bmdh, 'discovery')
        self.mox.StubOutWithMock(bmdh, 'login_iscsi')
        self.mox.StubOutWithMock(bmdh, 'logout_iscsi')
        self.mox.StubOutWithMock(bmdh, 'work_on_disk')

        class TestException(Exception):
            pass

        bmdh.get_dev(address, port, iqn, lun).AndReturn(dev)
        bmdh.get_image_mb(image_path).AndReturn(1)  # < root_mb
        bmdh.discovery(address, port)
        bmdh.login_iscsi(address, port, iqn)
        bmdh.work_on_disk(dev, root_mb, swap_mb, image_path).\
                AndRaise(TestException)
        bmdh.logout_iscsi(address, port, iqn)
        self.mox.ReplayAll()

        self.assertRaises(TestException, bmdh.deploy, address, port, iqn, lun,
                          image_path, pxe_config_path, root_mb, swap_mb)
    def test_always_logout_iscsi(self):
        """logout_iscsi() must be called once login_iscsi() is called."""
        address = "127.0.0.1"
        port = 3306
        iqn = "iqn.xyz"
        lun = 1
        image_path = "/tmp/xyz/image"
        pxe_config_path = "/tmp/abc/pxeconfig"
        root_mb = 128
        swap_mb = 64

        dev = "/dev/fake"

        self.mox.StubOutWithMock(bmdh, "get_dev")
        self.mox.StubOutWithMock(bmdh, "get_image_mb")
        self.mox.StubOutWithMock(bmdh, "discovery")
        self.mox.StubOutWithMock(bmdh, "login_iscsi")
        self.mox.StubOutWithMock(bmdh, "logout_iscsi")
        self.mox.StubOutWithMock(bmdh, "work_on_disk")

        class TestException(Exception):
            pass

        bmdh.get_dev(address, port, iqn, lun).AndReturn(dev)
        bmdh.get_image_mb(image_path).AndReturn(1)  # < root_mb
        bmdh.discovery(address, port)
        bmdh.login_iscsi(address, port, iqn)
        bmdh.work_on_disk(dev, root_mb, swap_mb, image_path).AndRaise(TestException)
        bmdh.logout_iscsi(address, port, iqn)
        self.mox.ReplayAll()

        self.assertRaises(
            TestException, bmdh.deploy, address, port, iqn, lun, image_path, pxe_config_path, root_mb, swap_mb
        )
    def test_always_logout_iscsi(self):
        """logout_iscsi() must be called once login_iscsi() is called."""
        address = '127.0.0.1'
        port = 3306
        iqn = 'iqn.xyz'
        lun = 1
        image_path = '/tmp/xyz/image'
        pxe_config_path = '/tmp/abc/pxeconfig'
        root_mb = 128
        swap_mb = 64
        ephemeral_mb = 256

        dev = '/dev/fake'

        self.mox.StubOutWithMock(bmdh, 'get_dev')
        self.mox.StubOutWithMock(bmdh, 'get_image_mb')
        self.mox.StubOutWithMock(bmdh, 'discovery')
        self.mox.StubOutWithMock(bmdh, 'login_iscsi')
        self.mox.StubOutWithMock(bmdh, 'logout_iscsi')
        self.mox.StubOutWithMock(bmdh, 'work_on_disk')

        class TestException(Exception):
            pass

        bmdh.get_dev(address, port, iqn, lun).AndReturn(dev)
        bmdh.get_image_mb(image_path).AndReturn(1)  # < root_mb
        bmdh.discovery(address, port)
        bmdh.login_iscsi(address, port, iqn)
        bmdh.work_on_disk(dev, root_mb, swap_mb, ephemeral_mb, image_path).\
                AndRaise(TestException)
        bmdh.logout_iscsi(address, port, iqn)
        self.mox.ReplayAll()

        self.assertRaises(TestException,
                         bmdh.deploy,
                         address, port, iqn, lun, image_path,
                         pxe_config_path, root_mb, swap_mb, ephemeral_mb)