libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anthonys...@apache.org
Subject [11/51] [abbrv] libcloud git commit: added tests for deploy and detete servers
Date Wed, 31 Oct 2018 03:11:22 GMT
added tests for deploy and detete servers


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/273486d0
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/273486d0
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/273486d0

Branch: refs/heads/trunk
Commit: 273486d090ec5604e5a805da845fa7f2d95c814b
Parents: 141d235
Author: mitch <mitch.raful@itaas.dimensiondata.com>
Authored: Fri Aug 31 13:55:29 2018 -0400
Committer: mitch <mitch.raful@itaas.dimensiondata.com>
Committed: Fri Aug 31 13:55:29 2018 -0400

----------------------------------------------------------------------
 libcloud/common/nttcis.py          |  4 +-
 libcloud/compute/drivers/nttcis.py | 27 +++++++-----
 tests/lib_create_test.py           | 42 +++++++++++++++++++
 tests/lib_edit_test.py             | 74 ++++++++++++++++++++++++++++++++-
 tests/lib_list_test.py             | 33 ++++++++++++++-
 5 files changed, 164 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/273486d0/libcloud/common/nttcis.py
----------------------------------------------------------------------
diff --git a/libcloud/common/nttcis.py b/libcloud/common/nttcis.py
index 191309f..e48cbb1 100644
--- a/libcloud/common/nttcis.py
+++ b/libcloud/common/nttcis.py
@@ -593,12 +593,14 @@ class NttCisConnection(ConnectionUserAndKey):
         cnt = 0
         result = None
         object_state = None
+        state = state.lower()
         while cnt < timeout / poll_interval:
             result = func(*args, **kwargs)
             if isinstance(result, Node):
                 object_state = result.state
             else:
-                object_state = result.status
+                # BUG: need to use result.status.lower() or will never match if client uses
lower case
+                object_state = result.status.lower()
 
             if object_state is state or object_state in state:
                 return result

http://git-wip-us.apache.org/repos/asf/libcloud/blob/273486d0/libcloud/compute/drivers/nttcis.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/nttcis.py b/libcloud/compute/drivers/nttcis.py
index 4866e76..1048eaa 100644
--- a/libcloud/compute/drivers/nttcis.py
+++ b/libcloud/compute/drivers/nttcis.py
@@ -1348,6 +1348,7 @@ class NttCisNodeDriver(NodeDriver):
 
     def ex_create_anti_affinity_rule(self, node_list):
         """
+        Edited to work with api 2.x.  No longer supports 1.0
         Create an anti affinity rule given a list of nodes
         Anti affinity rules ensure that servers will not reside
         on the same VMware ESX host
@@ -1360,16 +1361,16 @@ class NttCisNodeDriver(NodeDriver):
         """
         if not isinstance(node_list, (list, tuple)):
             raise TypeError("Node list must be a list or a tuple.")
-        anti_affinity_xml_request = ET.Element('NewAntiAffinityRule',
-                                               {'xmlns': SERVER_NS})
+        anti_affinity_xml_request = ET.Element('createAntiAffinityRule',
+                                               {'xmlns': TYPES_URN})
         for node in node_list:
             ET.SubElement(anti_affinity_xml_request, 'serverId').text = \
                 self._node_to_node_id(node)
-        result = self.connection.request_with_orgId_api_1(
-            'antiAffinityRule',
+        result = self.connection.request_with_orgId_api_2(
+            'server/createAntiAffinityRule',
             method='POST',
             data=ET.tostring(anti_affinity_xml_request)).object
-        response_code = findtext(result, 'result', GENERAL_NS)
+        response_code = findtext(result, 'responseCode', TYPES_URN)
         return response_code in ['IN_PROGRESS', 'SUCCESS']
 
     def ex_delete_anti_affinity_rule(self, anti_affinity_rule):
@@ -1382,12 +1383,16 @@ class NttCisNodeDriver(NodeDriver):
 
         :rtype: ``bool``
         """
-        rule_id = self._anti_affinity_rule_to_anti_affinity_rule_id(
-            anti_affinity_rule)
-        result = self.connection.request_with_orgId_api_1(
-            'antiAffinityRule/%s?delete' % (rule_id),
-            method='GET').object
-        response_code = findtext(result, 'result', GENERAL_NS)
+        rule_id = anti_affinity_rule
+        #rule_id = self._anti_affinity_rule_to_anti_affinity_rule_id(
+        #    anti_affinity_rule)
+        update_node = ET.Element('deleteAntiAffinityRule', {"xmlns": TYPES_URN})
+        update_node.set('id', rule_id)
+        result = self.connection.request_with_orgId_api_2(
+            'server/deleteAntiAffinityRule',
+            method='POST',
+            data=ET.tostring(update_node)).object
+        response_code = findtext(result, 'responseCode', TYPES_URN)
         return response_code in ['IN_PROGRESS', 'SUCCESS']
 
     def ex_list_anti_affinity_rules(self, network=None, network_domain=None,

http://git-wip-us.apache.org/repos/asf/libcloud/blob/273486d0/tests/lib_create_test.py
----------------------------------------------------------------------
diff --git a/tests/lib_create_test.py b/tests/lib_create_test.py
new file mode 100644
index 0000000..a2e85ac
--- /dev/null
+++ b/tests/lib_create_test.py
@@ -0,0 +1,42 @@
+import pytest
+import libcloud
+from libcloud import loadbalancer
+from libcloud.common.nttcis import NttCisAPIException, NttCisVlan
+
+
+def test_deploy_vlan(compute_driver, vlan_name, network_domain_id, base_ipv4_addr):
+    network_domain = compute_driver.ex_get_network_domain(network_domain_id)
+    result = compute_driver.ex_create_vlan(network_domain, vlan_name, base_ipv4_addr)
+    assert isinstance(result, NttCisVlan)
+    compute_driver.ex_wait_for_state('normal', compute_driver.ex_get_vlan, 2, 60, result.id)
+    return result
+
+
+def test_deploy_server(compute_driver):
+    image_id = "81a36aa0-555c-4735-b965-4b64fcf0ac8f"
+    images = compute_driver.list_images(location='EU6')
+    image = [i for i in images if i.id == image_id]
+    domain_name = 'sdk_test_1'
+    domains = compute_driver.ex_list_network_domains(location='EU6')
+    net_domain = [d for d in domains if d.name == domain_name]
+    psswd = 'Snmpv2c!'
+    vlan_name = "sdk_vlan1"
+    vlans = compute_driver.ex_list_vlans()
+    vlan = [v for v in vlans if v.name == vlan_name]
+    new_node = compute_driver.create_node("ubuntu", image[0], psswd, ex_description="auto_created_server",
+                                         ex_network_domain=net_domain[0], ex_primary_nic_vlan=vlan[0])
+    compute_driver.ex_wait_for_state('running', compute_driver.ex_get_node_by_id, 2, 300,
new_node.id)
+    assert new_node.state == 'running'
+
+
+def test_delete_server(compute_driver):
+    server = compute_driver.list_nodes(ex_name="ubuntu")[0]
+    shut_result = compute_driver.ex_shutdown_graceful(server)
+    assert shut_result is True
+    compute_driver.ex_wait_for_state('stopped', compute_driver.ex_get_node_by_id, 2, 45,
server.id)
+    result = compute_driver.destroy_node(server)
+    assert result is True
+    compute_driver.ex_wait_for_state('terminated', compute_driver.ex_get_node_by_id, 2, 240,
server.id)
+
+
+def test_deploy_firewall_rule
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/273486d0/tests/lib_edit_test.py
----------------------------------------------------------------------
diff --git a/tests/lib_edit_test.py b/tests/lib_edit_test.py
index c86d3ce..9c82c6d 100644
--- a/tests/lib_edit_test.py
+++ b/tests/lib_edit_test.py
@@ -1,7 +1,8 @@
 import pytest
 import libcloud
 from libcloud import loadbalancer
-from libcloud.common.nttcis import NttCisAPIException
+from libcloud.common.nttcis import NttCisAPIException, NttCisVlan
+from tests.lib_create_test import test_deploy_vlan
 
 
 def test_disable_node_snapshot(compute_driver):
@@ -171,7 +172,76 @@ def test_remove_scsi_controller(compute_driver):
 
 
 def test_update_vmware_tools(compute_driver):
-    pass
+    node = compute_driver.ex_get_node_by_id('803e5e00-b22a-450a-8827-066ff15ec977')
+    result = compute_driver.ex_update_vm_tools(node)
+    assert result is True
+    compute_driver.ex_wait_for_state('running', compute_driver.ex_get_node_by_id, 2, 240,
node.id)
+
+
+def test_add_node_to_vlan(compute_driver):
+    vlan = test_deploy_vlan(compute_driver, "test_vlan_create", "6aafcf08-cb0b-432c-9c64-7371265db086",
"10.0.2.0")
+    assert isinstance(vlan, NttCisVlan)
+    node = compute_driver.ex_get_node_by_id('803e5e00-b22a-450a-8827-066ff15ec977')
+    shut_result = compute_driver.ex_shutdown_graceful(node)
+    assert shut_result is True
+    compute_driver.ex_wait_for_state('stopped', compute_driver.ex_get_node_by_id, 2, 45,
node.id)
+    result = compute_driver.ex_attach_node_to_vlan(node, vlan=vlan)
+    assert result is True
+    compute_driver.ex_wait_for_state('stopped', compute_driver.ex_get_node_by_id, 2, 240,
node.id)
+    result = compute_driver.ex_start_node(node)
+    assert result is True
+
+
+def test_remove_nic(compute_driver):
+    node = compute_driver.ex_get_node_by_id('803e5e00-b22a-450a-8827-066ff15ec977')
+    shut_result = compute_driver.ex_shutdown_graceful(node)
+    assert shut_result is True
+    compute_driver.ex_wait_for_state('stopped', compute_driver.ex_get_node_by_id, 2, 45,
node.id)
+    result = compute_driver.ex_disable_snapshots(node.id)
+    assert result is True
+    result = compute_driver.ex_destroy_nic("e9cdea1b-c4f2-4769-93a8-57e24248abdd")
+    assert result is True
+    compute_driver.ex_wait_for_state('stopped', compute_driver.ex_get_node_by_id, 2, 240,
node.id)
+    result = compute_driver.ex_start_node(node)
+    assert result is True
+
+""""
+No wayt to get nic id's via libcloud
+def test_exchange_nic_vlans(compute_driver):
+    node = compute_driver.ex_get_node_by_id('803e5e00-b22a-450a-8827-066ff15ec977')
+    print(node.extra)
+"""
+
+
+def test_change_nic_type(compute_driver):
+    nic_id = "7a27b2b1-7b20-404f-be53-4695023c2734"
+    nic_type = 'VMXNET3'
+    node = compute_driver.ex_get_node_by_id('803e5e00-b22a-450a-8827-066ff15ec977')
+    shut_result = compute_driver.ex_shutdown_graceful(node)
+    assert shut_result is True
+    compute_driver.ex_wait_for_state('stopped', compute_driver.ex_get_node_by_id, 2, 45,
node.id)
+    result = compute_driver.ex_change_nic_network_adapter(nic_id, nic_type)
+    assert result is True
+    compute_driver.ex_wait_for_state('stopped', compute_driver.ex_get_node_by_id, 2, 240,
node.id)
+    result = compute_driver.ex_start_node(node)
+    assert result is True
+
+
+def test_create_anti_affinity_rule(compute_driver):
+    server1 = compute_driver.ex_get_node_by_id("d0425097-202f-4bba-b268-c7a73b8da129")
+    server2 = compute_driver.ex_get_node_by_id("803e5e00-b22a-450a-8827-066ff15ec977")
+    servers = [server1, server2]
+    result = compute_driver.ex_create_anti_affinity_rule(servers)
+    assert isinstance(result, )
+
+
+def test_delete_anti_affinity_rule(compute_driver):
+    anti_affinity_rule = "40d83160-0fa2-418d-a73e-5f15fe1354fc"
+    result = compute_driver.ex_delete_anti_affinity_rule(anti_affinity_rule)
+    assert result is True
+
+
+
 
 
 def test_list_locations(compute_driver):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/273486d0/tests/lib_list_test.py
----------------------------------------------------------------------
diff --git a/tests/lib_list_test.py b/tests/lib_list_test.py
index f664068..d86b96b 100644
--- a/tests/lib_list_test.py
+++ b/tests/lib_list_test.py
@@ -61,6 +61,10 @@ def test_list_images(compute_driver):
     assert isinstance(images, list) and len(images) > 0
 
 
+def test_list_os(compute_driver):
+    oss = compute_driver.ex_list_os(location='EU6')
+
+
 def test_list_node_by_image(compute_driver):
     nodes = compute_driver.list_nodes(ex_image='81a36aa0-555c-4735-b965-4b64fcf0ac8f')
     print()
@@ -127,7 +131,7 @@ def test_list_node_state(compute_driver):
     assert isinstance(nodes, list) and len(nodes) > 0
 
 
-def test_list_netwokr_domain_id(compute_driver):
+def test_list_network_domain_id(compute_driver):
     nodes = compute_driver.list_nodes(ex_network_domain='6aafcf08-cb0b-432c-9c64-7371265db086')
     print()
     for node in nodes:
@@ -268,6 +272,32 @@ def test_list_snapshots(compute_driver):
         print(snapshot)
         assert 'expiry_time' in snapshot
 
+
+def test_list_nics(compute_driver):
+    result = compute_driver.ex_list_
+
+
+def test_list_vlans(compute_driver):
+    vlans = compute_driver.ex_list_vlans()
+    print(vlans)
+    assert isinstance(vlans, list)
+
+
+def test_list_anti_affinity_rules(compute_driver):
+    # Could use network domain or node but not both
+    # net_domain = compute_driver.ex_get_network_domain('6aafcf08-cb0b-432c-9c64-7371265db086')
+    node = compute_driver.ex_get_node_by_id("803e5e00-b22a-450a-8827-066ff15ec977")
+    anti_affinity_rules = compute_driver.ex_list_anti_affinity_rules(node=node)
+    assert len(anti_affinity_rules) > 1
+
+
+def test_list_no_anti_affinity_rules(compute_driver):
+    # Could use network domain or node but not both
+    # net_domain = compute_driver.ex_get_network_domain('6aafcf08-cb0b-432c-9c64-7371265db086')
+    node = compute_driver.ex_get_node_by_id("803e5e00-b22a-450a-8827-066ff15ec977")
+    anti_affinity_rules = compute_driver.ex_list_anti_affinity_rules(node=node)
+    assert len(anti_affinity_rules) == 0
+
 """
 def test_list_sizes(compute_driver):
     properties = compute_driver.list_locations()
@@ -275,7 +305,6 @@ def test_list_sizes(compute_driver):
         print(property)
 """
 
-
 def test_images(compute_driver):
     images = compute_driver.list_images()
     print()


Mime
View raw message