Example #1
0
 def setUp(self):
     Opsource.connectionCls.conn_classes = (None, OpsourceMockHttp)
     OpsourceMockHttp.type = None
     self.driver = Opsource(*OPSOURCE_PARAMS)
Example #2
0
class OpsourceTests(unittest.TestCase, TestCaseMixin):
    def setUp(self):
        Opsource.connectionCls.conn_classes = (None, OpsourceMockHttp)
        OpsourceMockHttp.type = None
        self.driver = Opsource(*OPSOURCE_PARAMS)

    def test_invalid_creds(self):
        OpsourceMockHttp.type = 'UNAUTHORIZED'
        try:
            self.driver.list_nodes()
            self.assertTrue(
                False
            )  # Above command should have thrown an InvalidCredsException
        except InvalidCredsError:
            pass

    def test_list_sizes_response(self):
        OpsourceMockHttp.type = None
        ret = self.driver.list_sizes()
        self.assertEqual(len(ret), 1)
        size = ret[0]
        self.assertEqual(size.name, 'default')

    def test_reboot_node_response(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = node.reboot()
        self.assertTrue(ret is True)

    def test_reboot_node_response_INPROGRESS(self):
        OpsourceMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            node.reboot()
            self.assertTrue(
                False)  # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            pass

    def test_destroy_node_response(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = node.destroy()
        self.assertTrue(ret is True)

    def test_destroy_node_response_INPROGRESS(self):
        OpsourceMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            node.destroy()
            self.assertTrue(
                False)  # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            pass

    def test_create_node_response(self):
        rootPw = NodeAuthPassword('pass123')
        image = self.driver.list_images()[0]
        network = self.driver.ex_list_networks()[0]
        node = self.driver.create_node(name='test2',
                                       image=image,
                                       auth=rootPw,
                                       ex_description='test2 node',
                                       ex_network=network,
                                       ex_isStarted=False)
        self.assertEqual(node.id, 'e75ead52-692f-4314-8725-c8a4f4d13a87')
        self.assertEqual(node.extra['status'].action, 'DEPLOY_SERVER')

    def test_ex_shutdown_graceful(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = self.driver.ex_shutdown_graceful(node)
        self.assertTrue(ret is True)

    def test_ex_shutdown_graceful_INPROGRESS(self):
        OpsourceMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            self.driver.ex_shutdown_graceful(node)
            self.assertTrue(
                False)  # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            pass

    def test_ex_start_node(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = self.driver.ex_start_node(node)
        self.assertTrue(ret is True)

    def test_ex_start_node_INPROGRESS(self):
        OpsourceMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            self.driver.ex_start_node(node)
            self.assertTrue(
                False)  # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            pass

    def test_ex_power_off(self):
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        ret = self.driver.ex_power_off(node)
        self.assertTrue(ret is True)

    def test_ex_power_off_INPROGRESS(self):
        OpsourceMockHttp.type = 'INPROGRESS'
        node = Node(id='11',
                    name=None,
                    state=None,
                    public_ips=None,
                    private_ips=None,
                    driver=self.driver)
        try:
            self.driver.ex_power_off(node)
            self.assertTrue(
                False)  # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            pass

    def test_ex_list_networks(self):
        nets = self.driver.ex_list_networks()
        self.assertEqual(nets[0].name, 'test-net1')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_node_public_ip(self):
        nodes = self.driver.list_nodes()
        node = [
            n for n in nodes if n.id == 'abadbc7e-9e10-46ca-9d4a-194bcc6b6c16'
        ][0]
        self.assertEqual(node.public_ips[0], '200.16.132.7')
class OpsourceTests(unittest.TestCase, TestCaseMixin):

    def setUp(self):
        Opsource.connectionCls.conn_classes = (None, OpsourceMockHttp)
        OpsourceMockHttp.type = None
        self.driver = Opsource(*OPSOURCE_PARAMS)

    def test_invalid_creds(self):
        OpsourceMockHttp.type = 'UNAUTHORIZED'
        try:
            self.driver.list_nodes()
            self.assertTrue(False) # Above command should have thrown an InvalidCredsException
        except InvalidCredsError:
            self.assertTrue(True)

    def test_list_sizes_response(self):
        OpsourceMockHttp.type = None
        ret = self.driver.list_sizes()
        self.assertEqual(len(ret), 1)
        size = ret[0]
        self.assertEqual(size.name, 'default')

    def test_reboot_node_response(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = node.reboot()
        self.assertTrue(ret is True)

    def test_reboot_node_response_INPROGRESS(self):
        OpsourceMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            node.reboot()
            self.assertTrue(False) # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            self.assertTrue(True)

    def test_destroy_node_response(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = node.destroy()
        self.assertTrue(ret is True)

    def test_destroy_node_response_INPROGRESS(self):
        OpsourceMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            node.destroy()
            self.assertTrue(False) # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            self.assertTrue(True)

    def test_create_node_response(self):
        rootPw = NodeAuthPassword('pass123')
        image = self.driver.list_images()[0]
        network = self.driver.ex_list_networks()[0]
        node = self.driver.create_node(name='test2', image=image, auth=rootPw,
                                ex_description='test2 node', ex_network=network,
                                ex_isStarted=False)
        self.assertEqual(node.id, 'e75ead52-692f-4314-8725-c8a4f4d13a87')
        self.assertEqual(node.extra['status'].action, 'DEPLOY_SERVER')

    def test_ex_shutdown_graceful(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_shutdown_graceful(node)
        self.assertTrue(ret is True)

    def test_ex_shutdown_graceful_INPROGRESS(self):
        OpsourceMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_shutdown_graceful(node)
            self.assertTrue(False) # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            self.assertTrue(True)

    def test_ex_start_node(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_start_node(node)
        self.assertTrue(ret is True)

    def test_ex_start_node_INPROGRESS(self):
        OpsourceMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_start_node(node)
            self.assertTrue(False) # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            self.assertTrue(True)

    def test_ex_power_off(self):
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_power_off(node)
        self.assertTrue(ret is True)

    def test_ex_power_off_INPROGRESS(self):
        OpsourceMockHttp.type = 'INPROGRESS'
        node = Node(id='11', name=None, state=None,
                    public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_power_off(node)
            self.assertTrue(False) # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            self.assertTrue(True)

    def test_ex_list_networks(self):
        nets = self.driver.ex_list_networks()
        self.assertEqual(nets[0].name, 'test-net1')
        self.assertTrue(isinstance(nets[0].location, NodeLocation))

    def test_node_public_ip(self):
        nodes = self.driver.list_nodes()
        for node in nodes:
            if node.id == "abadbc7e-9e10-46ca-9d4a-194bcc6b6c16":
                self.assertEqual(node.public_ips[0], '200.16.132.7')
            else:
                self.assertEqual(len(node.public_ips), 0)
 def setUp(self):
     Opsource.connectionCls.conn_classes = (None, OpsourceMockHttp)
     OpsourceMockHttp.type = None
     self.driver = Opsource(*OPSOURCE_PARAMS)
Example #5
0
class OpsourceTests(unittest.TestCase, TestCaseMixin):
    def setUp(self):
        Opsource.connectionCls.conn_classes = (None, OpsourceMockHttp)
        OpsourceMockHttp.type = None
        self.driver = Opsource(*OPSOURCE_PARAMS)

    def test_invalid_creds(self):
        OpsourceMockHttp.type = "UNAUTHORIZED"
        try:
            self.driver.list_nodes()
            self.assertTrue(False)  # Above command should have thrown an InvalidCredsException
        except InvalidCredsError:
            self.assertTrue(True)

    def test_list_sizes_response(self):
        OpsourceMockHttp.type = None
        ret = self.driver.list_sizes()
        self.assertEqual(len(ret), 1)
        size = ret[0]
        self.assertEqual(size.name, "default")

    def test_reboot_node_response(self):
        node = Node(id="11", name=None, state=None, public_ips=None, private_ips=None, driver=self.driver)
        ret = node.reboot()
        self.assertTrue(ret is True)

    def test_reboot_node_response_INPROGRESS(self):
        OpsourceMockHttp.type = "INPROGRESS"
        node = Node(id="11", name=None, state=None, public_ips=None, private_ips=None, driver=self.driver)
        try:
            node.reboot()
            self.assertTrue(False)  # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            self.assertTrue(True)

    def test_destroy_node_response(self):
        node = Node(id="11", name=None, state=None, public_ips=None, private_ips=None, driver=self.driver)
        ret = node.destroy()
        self.assertTrue(ret is True)

    def test_destroy_node_response_INPROGRESS(self):
        OpsourceMockHttp.type = "INPROGRESS"
        node = Node(id="11", name=None, state=None, public_ips=None, private_ips=None, driver=self.driver)
        try:
            node.destroy()
            self.assertTrue(False)  # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            self.assertTrue(True)

    def test_create_node_response(self):
        rootPw = NodeAuthPassword("pass123")
        image = self.driver.list_images()[0]
        network = self.driver.ex_list_networks()[0]
        node = self.driver.create_node(
            name="test2", image=image, auth=rootPw, ex_description="test2 node", ex_network=network, ex_isStarted=False
        )
        self.assertEqual(node.id, "e75ead52-692f-4314-8725-c8a4f4d13a87")
        self.assertEqual(node.extra["status"].action, "DEPLOY_SERVER")

    def test_ex_shutdown_graceful(self):
        node = Node(id="11", name=None, state=None, public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_shutdown_graceful(node)
        self.assertTrue(ret is True)

    def test_ex_shutdown_graceful_INPROGRESS(self):
        OpsourceMockHttp.type = "INPROGRESS"
        node = Node(id="11", name=None, state=None, public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_shutdown_graceful(node)
            self.assertTrue(False)  # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            self.assertTrue(True)

    def test_ex_start_node(self):
        node = Node(id="11", name=None, state=None, public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_start_node(node)
        self.assertTrue(ret is True)

    def test_ex_start_node_INPROGRESS(self):
        OpsourceMockHttp.type = "INPROGRESS"
        node = Node(id="11", name=None, state=None, public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_start_node(node)
            self.assertTrue(False)  # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            self.assertTrue(True)

    def test_ex_power_off(self):
        node = Node(id="11", name=None, state=None, public_ips=None, private_ips=None, driver=self.driver)
        ret = self.driver.ex_power_off(node)
        self.assertTrue(ret is True)

    def test_ex_power_off_INPROGRESS(self):
        OpsourceMockHttp.type = "INPROGRESS"
        node = Node(id="11", name=None, state=None, public_ips=None, private_ips=None, driver=self.driver)
        try:
            self.driver.ex_power_off(node)
            self.assertTrue(False)  # above command should have thrown OpsourceAPIException
        except OpsourceAPIException:
            self.assertTrue(True)

    def test_ex_list_networks(self):
        nets = self.driver.ex_list_networks()
        self.assertEqual(nets[0].name, "test-net1")
        self.assertTrue(isinstance(nets[0].location, NodeLocation))