Ejemplo n.º 1
0
 def setUp(self):
     super(TestCoraidRESTClient, self).setUp()
     self.stubs.Set(cookielib, 'CookieJar', lambda *_: True)
     self.stubs.Set(urllib2, 'build_opener', lambda *_: True)
     self.stubs.Set(urllib2, 'HTTPCookieProcessor', lambda *_: True)
     self.stubs.Set(CoraidRESTClient, '_login', lambda *_: True)
     self.rest_mock = self.mox.CreateMockAnything()
     self.stubs.Set(coraid, 'CoraidRESTClient',
                    lambda *_, **__: self.rest_mock)
     self.drv = CoraidRESTClient(fake_esm_ipaddress, fake_esm_username,
                                 fake_esm_group, fake_esm_password)
Ejemplo n.º 2
0
 def setUp(self):
     super(TestCoraidRESTClient, self).setUp()
     self.stubs.Set(cookielib, "CookieJar", lambda *_: True)
     self.stubs.Set(urllib2, "build_opener", lambda *_: True)
     self.stubs.Set(urllib2, "HTTPCookieProcessor", lambda *_: True)
     self.stubs.Set(CoraidRESTClient, "_login", lambda *_: True)
     self.rest_mock = self.mox.CreateMockAnything()
     self.stubs.Set(coraid, "CoraidRESTClient", lambda *_, **__: self.rest_mock)
     self.drv = CoraidRESTClient(fake_esm_ipaddress, fake_esm_username, fake_esm_group, fake_esm_password)
Ejemplo n.º 3
0
class TestCoraidRESTClient(test.TestCase):
    def setUp(self):
        super(TestCoraidRESTClient, self).setUp()
        self.stubs.Set(cookielib, "CookieJar", lambda *_: True)
        self.stubs.Set(urllib2, "build_opener", lambda *_: True)
        self.stubs.Set(urllib2, "HTTPCookieProcessor", lambda *_: True)
        self.stubs.Set(CoraidRESTClient, "_login", lambda *_: True)
        self.rest_mock = self.mox.CreateMockAnything()
        self.stubs.Set(coraid, "CoraidRESTClient", lambda *_, **__: self.rest_mock)
        self.drv = CoraidRESTClient(fake_esm_ipaddress, fake_esm_username, fake_esm_group, fake_esm_password)

    def test__get_group_id(self):
        setattr(self.rest_mock, "_get_group_id", lambda *_: True)
        self.assertEquals(self.drv._get_group_id(fake_esm_group, fake_login_reply), fake_group_id)

    def test__set_group(self):
        setattr(self.rest_mock, "_set_group", lambda *_: fake_group_id)
        self.stubs.Set(CoraidRESTClient, "_esm", lambda *_: fake_login_reply)
        self.drv._set_group(fake_login_reply)

    def test__set_group_fails_no_group(self):
        setattr(self.rest_mock, "_set_group", lambda *_: False)
        self.stubs.Set(CoraidRESTClient, "_esm", lambda *_: fake_login_reply_group_fail)
        self.assertRaises(CoraidESMException, self.drv._set_group, fake_login_reply_group_fail)

    def test__configure(self):
        setattr(self.rest_mock, "_configure", lambda *_: True)
        self.stubs.Set(CoraidRESTClient, "_esm", lambda *_: fake_esm_success)
        self.drv._configure(fake_configure_data)

    def test__get_volume_info(self):
        setattr(self.rest_mock, "_get_volume_info", lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, "_esm", lambda *_: fake_esm_fetch)
        self.drv._get_volume_info(fake_volume_name)

    def test__get_lun_address(self):
        setattr(self.rest_mock, "_get_lun_address", lambda *_: fake_lun_info)
        self.stubs.Set(CoraidRESTClient, "_get_volume_info", lambda *_: fake_volume_info)
        self.drv._get_lun_address(fake_volume_name)

    def test_create_lun(self):
        setattr(self.rest_mock, "create_lun", lambda *_: True)
        self.stubs.Set(CoraidRESTClient, "_configure", lambda *_: fake_esm_success)
        self.rest_mock.create_lun(fake_volume_name, "10", fake_repository_name)
        self.drv.create_lun(fake_volume_name, "10", fake_repository_name)

    def test_delete_lun(self):
        setattr(self.rest_mock, "delete_lun", lambda *_: True)
        self.stubs.Set(CoraidRESTClient, "_get_volume_info", lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, "_configure", lambda *_: fake_esm_success)
        self.rest_mock.delete_lun(fake_volume_name)
        self.drv.delete_lun(fake_volume_name)

    def test_create_snapshot(self):
        setattr(self.rest_mock, "create_snapshot", lambda *_: True)
        self.stubs.Set(CoraidRESTClient, "_get_volume_info", lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, "_configure", lambda *_: fake_esm_success)
        self.drv.create_snapshot(fake_volume_name, fake_volume_name)

    def test_delete_snapshot(self):
        setattr(self.rest_mock, "delete_snapshot", lambda *_: True)
        self.stubs.Set(CoraidRESTClient, "_get_volume_info", lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, "_configure", lambda *_: fake_esm_success)
        self.drv.delete_snapshot(fake_volume_name)

    def test_create_volume_from_snapshot(self):
        setattr(self.rest_mock, "create_volume_from_snapshot", lambda *_: True)
        self.stubs.Set(CoraidRESTClient, "_get_volume_info", lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, "_configure", lambda *_: fake_esm_success)
        self.drv.create_volume_from_snapshot(fake_volume_name, fake_volume_name, fake_repository_name)
Ejemplo n.º 4
0
class TestCoraidRESTClient(test.TestCase):
    def setUp(self):
        super(TestCoraidRESTClient, self).setUp()
        self.stubs.Set(cookielib, 'CookieJar', lambda *_: True)
        self.stubs.Set(urllib2, 'build_opener', lambda *_: True)
        self.stubs.Set(urllib2, 'HTTPCookieProcessor', lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_login', lambda *_: True)
        self.rest_mock = self.mox.CreateMockAnything()
        self.stubs.Set(coraid, 'CoraidRESTClient',
                       lambda *_, **__: self.rest_mock)
        self.drv = CoraidRESTClient(fake_esm_ipaddress,
                                    fake_esm_username,
                                    fake_esm_group,
                                    fake_esm_password)

    def test__get_group_id(self):
        setattr(self.rest_mock, '_get_group_id',
                lambda *_: True)
        self.assertEquals(self.drv._get_group_id(fake_esm_group,
                                                 fake_login_reply),
                          fake_group_id)

    def test__set_group(self):
        setattr(self.rest_mock, '_set_group',
                lambda *_: fake_group_id)
        self.stubs.Set(CoraidRESTClient, '_admin_esm_cmd',
                       lambda *_: fake_login_reply)
        self.drv._set_group(fake_login_reply)

    def test__set_group_fails_no_group(self):
        setattr(self.rest_mock, '_set_group',
                lambda *_: False)
        self.stubs.Set(CoraidRESTClient, '_admin_esm_cmd',
                       lambda *_: fake_login_reply_group_fail)
        self.assertRaises(CoraidESMException,
                          self.drv._set_group,
                          fake_login_reply_group_fail)

    def test__configure(self):
        setattr(self.rest_mock, '_configure',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_esm_cmd',
                       lambda *_: fake_esm_success)
        self.drv._configure(fake_configure_data)

    def test__get_volume_info(self):
        setattr(self.rest_mock, '_get_volume_info',
                lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_esm_cmd',
                       lambda *_: fake_esm_fetch)
        self.drv._get_volume_info(fake_volume_name)

    def test__get_lun_address(self):
        setattr(self.rest_mock, '_get_lun_address',
                lambda *_: fake_lun_info)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.drv._get_lun_address(fake_volume_name)

    def test_create_lun(self):
        setattr(self.rest_mock, 'create_lun',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.rest_mock.create_lun(fake_volume_name, '10',
                                  fake_repository_name)
        self.drv.create_lun(fake_volume_name, '10',
                            fake_repository_name)

    def test_delete_lun(self):
        setattr(self.rest_mock, 'delete_lun',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.rest_mock.delete_lun(fake_volume_name)
        self.drv.delete_lun(fake_volume_name)

    def test_create_snapshot(self):
        setattr(self.rest_mock, 'create_snapshot',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.drv.create_snapshot(fake_volume_name,
                                 fake_volume_name)

    def test_delete_snapshot(self):
        setattr(self.rest_mock, 'delete_snapshot',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.drv.delete_snapshot(fake_volume_name)

    def test_create_volume_from_snapshot(self):
        setattr(self.rest_mock, 'create_volume_from_snapshot',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.drv.create_volume_from_snapshot(fake_volume_name,
                                             fake_volume_name,
                                             fake_repository_name)

    def test_resize_volume(self):
        setattr(self.rest_mock, 'resize_volume',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.drv.resize_volume(fake_volume_name,
                               '20')
Ejemplo n.º 5
0
class TestCoraidRESTClient(test.TestCase):
    def setUp(self):
        super(TestCoraidRESTClient, self).setUp()
        self.stubs.Set(cookielib, 'CookieJar', lambda *_: True)
        self.stubs.Set(urllib2, 'build_opener', lambda *_: True)
        self.stubs.Set(urllib2, 'HTTPCookieProcessor', lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_login', lambda *_: True)
        self.rest_mock = self.mox.CreateMockAnything()
        self.stubs.Set(coraid, 'CoraidRESTClient',
                       lambda *_, **__: self.rest_mock)
        self.drv = CoraidRESTClient(fake_esm_ipaddress, fake_esm_username,
                                    fake_esm_group, fake_esm_password)

    def test__get_group_id(self):
        setattr(self.rest_mock, '_get_group_id', lambda *_: True)
        self.assertEquals(
            self.drv._get_group_id(fake_esm_group, fake_login_reply),
            fake_group_id)

    def test__set_group(self):
        setattr(self.rest_mock, '_set_group', lambda *_: fake_group_id)
        self.stubs.Set(CoraidRESTClient, '_admin_esm_cmd',
                       lambda *_: fake_login_reply)
        self.drv._set_group(fake_login_reply)

    def test__set_group_fails_no_group(self):
        setattr(self.rest_mock, '_set_group', lambda *_: False)
        self.stubs.Set(CoraidRESTClient, '_admin_esm_cmd',
                       lambda *_: fake_login_reply_group_fail)
        self.assertRaises(CoraidESMException, self.drv._set_group,
                          fake_login_reply_group_fail)

    def test__configure(self):
        setattr(self.rest_mock, '_configure', lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_esm_cmd',
                       lambda *_: fake_esm_success)
        self.drv._configure(fake_configure_data)

    def test__get_volume_info(self):
        setattr(self.rest_mock, '_get_volume_info',
                lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_esm_cmd', lambda *_: fake_esm_fetch)
        self.drv._get_volume_info(fake_volume_name)

    def test__get_lun_address(self):
        setattr(self.rest_mock, '_get_lun_address', lambda *_: fake_lun_info)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.drv._get_lun_address(fake_volume_name)

    def test_create_lun(self):
        setattr(self.rest_mock, 'create_lun', lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.rest_mock.create_lun(fake_volume_name, '10', fake_repository_name)
        self.drv.create_lun(fake_volume_name, '10', fake_repository_name)

    def test_delete_lun_ok(self):
        """Test Delete Volume classic case."""
        setattr(self.rest_mock, 'delete_lun',
                lambda *_: self.mox.CreateMockAnything())
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.rest_mock.delete_lun(fake_volume_name)
        result = self.drv.delete_lun(fake_volume_name)
        self.assertTrue(result)

    def test_delete_lun_in_error(self):
        """Test Delete Volume in Error State."""
        setattr(self.rest_mock, 'delete_lun',
                lambda *_: self.mox.CreateMockAnything())
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: Exception)
        self.stubs.Set(CoraidRESTClient, '_check_esm_alive', lambda *_: True)
        self.rest_mock.delete_lun(fake_volume_name)
        result = self.drv.delete_lun(fake_volume_name)
        self.assertTrue(result)

    def test_delete_lun_esm_unavailable(self):
        """Test Delete Volume with ESM Unavailable."""
        setattr(self.rest_mock, 'delete_lun',
                lambda *_: self.mox.CreateMockAnything())
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: Exception)
        self.stubs.Set(CoraidRESTClient, '_check_esm_alive', lambda *_: False)
        self.rest_mock.delete_lun(fake_volume_name)
        result = self.drv.delete_lun(fake_volume_name)
        self.assertRaises(Exception, result)

    def test_create_snapshot(self):
        setattr(self.rest_mock, 'create_snapshot', lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.drv.create_snapshot(fake_volume_name, fake_volume_name)

    def test_delete_snapshot(self):
        setattr(self.rest_mock, 'delete_snapshot', lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.drv.delete_snapshot(fake_volume_name)

    def test_create_volume_from_snapshot(self):
        setattr(self.rest_mock, 'create_volume_from_snapshot', lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.drv.create_volume_from_snapshot(fake_volume_name,
                                             fake_volume_name,
                                             fake_repository_name)

    def test_resize_volume(self):
        setattr(self.rest_mock, 'resize_volume', lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.drv.resize_volume(fake_volume_name, '20')
Ejemplo n.º 6
0
class TestCoraidRESTClient(test.TestCase):
    def setUp(self):
        super(TestCoraidRESTClient, self).setUp()
        self.stubs.Set(cookielib, 'CookieJar', lambda *_: True)
        self.stubs.Set(urllib2, 'build_opener', lambda *_: True)
        self.stubs.Set(urllib2, 'HTTPCookieProcessor', lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_login', lambda *_: True)
        self.rest_mock = self.mox.CreateMockAnything()
        self.stubs.Set(coraid, 'CoraidRESTClient',
                       lambda *_, **__: self.rest_mock)
        self.drv = CoraidRESTClient(fake_esm_ipaddress,
                                    fake_esm_username,
                                    fake_esm_password)

    def test__configure(self):
        setattr(self.rest_mock, '_configure',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_esm',
                       lambda *_: fake_esm_success)
        self.drv._configure(fake_configure_data)

    def test__get_volume_info(self):
        setattr(self.rest_mock, '_get_volume_info',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_esm',
                       lambda *_: fake_esm_fetch)
        self.drv._get_volume_info(fake_volume_name)

    def test__get_lun_address(self):
        setattr(self.rest_mock, '_get_lun_address',
                lambda *_: fake_lun_info)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.drv._get_lun_address(fake_volume_name)

    def test_create_lun(self):
        setattr(self.rest_mock, 'create_lun',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.rest_mock.create_lun(fake_volume_name, '10',
                                  fake_repository_name)
        self.drv.create_lun(fake_volume_name, '10',
                            fake_repository_name)

    def test_delete_lun(self):
        setattr(self.rest_mock, 'delete_lun',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.rest_mock.delete_lun(fake_volume_name)
        self.drv.delete_lun(fake_volume_name)

    def test_create_snapshot(self):
        setattr(self.rest_mock, 'create_snapshot',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.drv.create_snapshot(fake_volume_name,
                                 fake_volume_name)

    def test_delete_snapshot(self):
        setattr(self.rest_mock, 'delete_snapshot',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.drv.delete_snapshot(fake_volume_name)

    def test_create_volume_from_snapshot(self):
        setattr(self.rest_mock, 'create_volume_from_snapshot',
                lambda *_: True)
        self.stubs.Set(CoraidRESTClient, '_get_volume_info',
                       lambda *_: fake_volume_info)
        self.stubs.Set(CoraidRESTClient, '_configure',
                       lambda *_: fake_esm_success)
        self.drv.create_volume_from_snapshot(fake_volume_name,
                                             fake_volume_name,
                                             fake_repository_name)