예제 #1
0
 def setUp(self):
     if self.url:
         args = ()
         kwargs = {'url': self.url}
     else:
         CloudFramesNodeDriver.connectionCls.conn_classes = (
             CloudFramesMockHttp, CloudFramesMockHttp)
         args = CLOUDFRAMES_PARAMS
         kwargs = {}
     self.driver = CloudFramesNodeDriver(*args, **kwargs)
예제 #2
0
 def test_connection(self):
     key, secret, secure, host, port = CLOUDFRAMES_PARAMS
     CloudFramesNodeDriver(key, secret, secure, host)
     CloudFramesNodeDriver(key, secret, secure, host, 80)
     self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                       key, secret, True, host, 80)
     CloudFramesNodeDriver(key, secret, secure, host, '80')
     self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                       key, secure=secure, host=host)
     self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                       secret=secret, secure=secure, host=host)
     CloudFramesNodeDriver(
         url='http://%s:%s@%s:80/appserver/xmlrpc' % (key, secret, host))
     CloudFramesNodeDriver(
         url='http://%s:%s@%s/appserver/xmlrpc' % (key, secret, host))
     self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                       key=key, secret=secret,
                       url='https://%s/appserver/xmlrpc' % host)
     self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                       key=key, secret=secret, secure=False,
                       url='https://%s/appserver/xmlrpc' % host)
     self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                       url='http://%s@%s/appserver/xmlrpc' % (key, host))
     CloudFramesNodeDriver(
         secret=secret, url='http://%s@%s/appserver/xmlrpc' % (key, host))
     self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                       url='http://%s/appserver/xmlrpc' % host)
     self.assertRaises(
         NotImplementedError, CloudFramesNodeDriver,
         secret=secret, url='http://%s/appserver/xmlrpc' % host)
     self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                       key=key, url='http://%s/appserver/xmlrpc' % host)
     CloudFramesNodeDriver(
         key=key, secret=secret, url='http://%s/appserver/xmlrpc' % host)
예제 #3
0
 def setUp(self):
     if self.url:
         args = ()
         kwargs = {'url': self.url}
     else:
         CloudFramesNodeDriver.connectionCls.conn_classes = (
             CloudFramesMockHttp, CloudFramesMockHttp)
         args = CLOUDFRAMES_PARAMS
         kwargs = {}
     self.driver = CloudFramesNodeDriver(*args, **kwargs)
예제 #4
0
class CloudFramesTests(unittest.TestCase, TestCaseMixin):

    should_list_locations = True
    should_have_pricing = False
    should_list_volumes = False

    def __init__(self, name, url=None):
        self.url = url
        super(CloudFramesTests, self).__init__(name)

    def setUp(self):
        if self.url:
            args = ()
            kwargs = {'url': self.url}
        else:
            CloudFramesNodeDriver.connectionCls.conn_classes = (
                CloudFramesMockHttp, CloudFramesMockHttp)
            args = CLOUDFRAMES_PARAMS
            kwargs = {}
        self.driver = CloudFramesNodeDriver(*args, **kwargs)

    def _retry_until_up(self, cmd, *args, **kwargs):
        """
        When testing against a live system, this will cause the given command
        to be retried until it succeeds.
        (Calls like snapshot/reboot will fail until the vm has started fully.)
        """
        now = datetime.datetime.now()
        while not (datetime.datetime.now() - now).seconds > START_TIMEOUT:
            try:
                return cmd(*args, **kwargs)
            except:
                pass
        else:
            raise Exception('VMWare tools did not become available in time')

    def test_connection(self):
        key, secret, secure, host, port = CLOUDFRAMES_PARAMS
        CloudFramesNodeDriver(key, secret, secure, host)
        CloudFramesNodeDriver(key, secret, secure, host, 80)
        self.assertRaises(NotImplementedError, CloudFramesNodeDriver, key,
                          secret, True, host, 80)
        CloudFramesNodeDriver(key, secret, secure, host, '80')
        self.assertRaises(NotImplementedError,
                          CloudFramesNodeDriver,
                          key,
                          secure=secure,
                          host=host)
        self.assertRaises(NotImplementedError,
                          CloudFramesNodeDriver,
                          secret=secret,
                          secure=secure,
                          host=host)
        CloudFramesNodeDriver(url='http://%s:%s@%s:80/appserver/xmlrpc' %
                              (key, secret, host))
        CloudFramesNodeDriver(url='http://%s:%s@%s/appserver/xmlrpc' %
                              (key, secret, host))
        self.assertRaises(NotImplementedError,
                          CloudFramesNodeDriver,
                          key=key,
                          secret=secret,
                          url='https://%s/appserver/xmlrpc' % host)
        self.assertRaises(NotImplementedError,
                          CloudFramesNodeDriver,
                          key=key,
                          secret=secret,
                          secure=False,
                          url='https://%s/appserver/xmlrpc' % host)
        self.assertRaises(NotImplementedError,
                          CloudFramesNodeDriver,
                          url='http://%s@%s/appserver/xmlrpc' % (key, host))
        CloudFramesNodeDriver(secret=secret,
                              url='http://%s@%s/appserver/xmlrpc' %
                              (key, host))
        self.assertRaises(NotImplementedError,
                          CloudFramesNodeDriver,
                          url='http://%s/appserver/xmlrpc' % host)
        self.assertRaises(NotImplementedError,
                          CloudFramesNodeDriver,
                          secret=secret,
                          url='http://%s/appserver/xmlrpc' % host)
        self.assertRaises(NotImplementedError,
                          CloudFramesNodeDriver,
                          key=key,
                          url='http://%s/appserver/xmlrpc' % host)
        CloudFramesNodeDriver(key=key,
                              secret=secret,
                              url='http://%s/appserver/xmlrpc' % host)

    def test_snapshot(self):
        nodes = [
            node for node in self.driver.list_nodes()
            if node.state == NodeState.RUNNING
        ]
        if not nodes:
            raise Exception('No running vm to test snapshotting')
        self._test_snapshot(nodes[0])

    def _test_snapshot(self, node):
        if self.url:
            self.assertEqual(len(self.driver.ex_list_snapshots(node)), 0)
        snapshot1 = self._retry_until_up(self.driver.ex_snapshot_node, node)
        self.assertTrue(isinstance(snapshot1, CloudFramesSnapshot))
        if self.url:
            self.assertEqual(len(self.driver.ex_list_snapshots(node)), 1)
        snapshot2 = self.driver.ex_snapshot_node(node)
        self.assertTrue(isinstance(snapshot2, CloudFramesSnapshot))
        if self.url:
            self.assertEqual(len(self.driver.ex_list_snapshots(node)), 2)
        self.driver.ex_destroy_snapshot(node, snapshot2)
        if self.url:
            self.assertEqual(len(self.driver.ex_list_snapshots(node)), 1)
        self.driver.ex_rollback_node(node, snapshot1)
        if self.url:
            self.assertEqual(len(self.driver.ex_list_snapshots(node)), 1)
        self.driver.ex_destroy_snapshot(node, snapshot1)

    def test_comprehensive(self):
        """
        Creates a node with the first location, image and size it finds.

        Then boots the node, reboots, creates two snapshots.
        Deletes one snapshot, rolls back to the other, then destroys the node.

        In between these operations it verifies the node status and lists.
        """
        if not self.url:
            return
        location = self.driver.list_locations()[0]
        self.assertTrue(isinstance(location, NodeLocation))
        image = self.driver.list_images()[0]
        self.assertTrue(isinstance(image, NodeImage))
        size = self.driver.list_sizes()[0]
        name = 'AUTOTEST_%s' % uuid.uuid4()
        node = self.driver.create_node(image=image,
                                       name=name,
                                       size=size,
                                       location=location)
        # give the node time to boot up and load the vmware tools
        self.assertTrue(isinstance(node, Node))
        self.assertTrue(node.id in [x.id for x in self.driver.list_nodes()])
        self.assertTrue(node.state == NodeState.RUNNING)
        self._test_snapshot(node)
        self._retry_until_up(self.driver.reboot_node, node)
        self.driver.destroy_node(node)
        self.assertFalse(node.id in [x.id for x in self.driver.list_nodes()])
예제 #5
0
class CloudFramesTests(unittest.TestCase, TestCaseMixin):

    should_list_locations = True
    should_have_pricing = False
    should_list_volumes = False

    def __init__(self, name, url=None):
        self.url = url
        super(CloudFramesTests, self).__init__(name)

    def setUp(self):
        if self.url:
            args = ()
            kwargs = {'url': self.url}
        else:
            CloudFramesNodeDriver.connectionCls.conn_classes = (
                CloudFramesMockHttp, CloudFramesMockHttp)
            args = CLOUDFRAMES_PARAMS
            kwargs = {}
        self.driver = CloudFramesNodeDriver(*args, **kwargs)

    def _retry_until_up(self, cmd, *args, **kwargs):
        """
        When testing against a live system, this will cause the given command
        to be retried until it succeeds.
        (Calls like snapshot/reboot will fail until the vm has started fully.)
        """
        now = datetime.datetime.now()
        while not (datetime.datetime.now() - now).seconds > START_TIMEOUT:
            try:
                return cmd(*args, **kwargs)
            except:
                pass
        else:
            raise Exception('VMWare tools did not become available in time')

    def test_connection(self):
        key, secret, secure, host, port = CLOUDFRAMES_PARAMS
        CloudFramesNodeDriver(key, secret, secure, host)
        CloudFramesNodeDriver(key, secret, secure, host, 80)
        self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                          key, secret, True, host, 80)
        CloudFramesNodeDriver(key, secret, secure, host, '80')
        self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                          key, secure=secure, host=host)
        self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                          secret=secret, secure=secure, host=host)
        CloudFramesNodeDriver(
            url='http://%s:%s@%s:80/appserver/xmlrpc' % (key, secret, host))
        CloudFramesNodeDriver(
            url='http://%s:%s@%s/appserver/xmlrpc' % (key, secret, host))
        self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                          key=key, secret=secret,
                          url='https://%s/appserver/xmlrpc' % host)
        self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                          key=key, secret=secret, secure=False,
                          url='https://%s/appserver/xmlrpc' % host)
        self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                          url='http://%s@%s/appserver/xmlrpc' % (key, host))
        CloudFramesNodeDriver(
            secret=secret, url='http://%s@%s/appserver/xmlrpc' % (key, host))
        self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                          url='http://%s/appserver/xmlrpc' % host)
        self.assertRaises(
            NotImplementedError, CloudFramesNodeDriver,
            secret=secret, url='http://%s/appserver/xmlrpc' % host)
        self.assertRaises(NotImplementedError, CloudFramesNodeDriver,
                          key=key, url='http://%s/appserver/xmlrpc' % host)
        CloudFramesNodeDriver(
            key=key, secret=secret, url='http://%s/appserver/xmlrpc' % host)

    def test_snapshot(self):
        nodes = [node for node in self.driver.list_nodes()
                 if node.state == NodeState.RUNNING]
        if not nodes:
            raise Exception('No running vm to test snapshotting')
        self._test_snapshot(nodes[0])

    def _test_snapshot(self, node):
        if self.url:
            self.assertEqual(len(self.driver.ex_list_snapshots(node)), 0)
        snapshot1 = self._retry_until_up(
            self.driver.ex_snapshot_node, node)
        self.assertTrue(isinstance(snapshot1, CloudFramesSnapshot))
        if self.url:
            self.assertEqual(len(self.driver.ex_list_snapshots(node)), 1)
        snapshot2 = self.driver.ex_snapshot_node(node)
        self.assertTrue(isinstance(snapshot2, CloudFramesSnapshot))
        if self.url:
            self.assertEqual(len(self.driver.ex_list_snapshots(node)), 2)
        self.driver.ex_destroy_snapshot(node, snapshot2)
        if self.url:
            self.assertEqual(len(self.driver.ex_list_snapshots(node)), 1)
        self.driver.ex_rollback_node(node, snapshot1)
        if self.url:
            self.assertEqual(len(self.driver.ex_list_snapshots(node)), 1)
        self.driver.ex_destroy_snapshot(node, snapshot1)

    def test_comprehensive(self):
        """
        Creates a node with the first location, image and size it finds.

        Then boots the node, reboots, creates two snapshots.
        Deletes one snapshot, rolls back to the other, then destroys the node.

        In between these operations it verifies the node status and lists.
        """
        if not self.url:
            return
        location = self.driver.list_locations()[0]
        self.assertTrue(isinstance(location, NodeLocation))
        image = self.driver.list_images()[0]
        self.assertTrue(isinstance(image, NodeImage))
        size = self.driver.list_sizes()[0]
        name = 'AUTOTEST_%s' % uuid.uuid4()
        node = self.driver.create_node(
            image=image, name=name, size=size, location=location)
        # give the node time to boot up and load the vmware tools
        self.assertTrue(isinstance(node, Node))
        self.assertTrue(node.id in [x.id for x in self.driver.list_nodes()])
        self.assertTrue(node.state == NodeState.RUNNING)
        self._test_snapshot(node)
        self._retry_until_up(self.driver.reboot_node, node)
        self.driver.destroy_node(node)
        self.assertFalse(node.id in [x.id for x in self.driver.list_nodes()])