Update federation tests and nova commands. 53/21753/1
authorThomas Duval <thomas.duval@orange.com>
Tue, 6 Sep 2016 13:52:54 +0000 (15:52 +0200)
committerThomas Duval <thomas.duval@orange.com>
Tue, 20 Sep 2016 08:38:37 +0000 (10:38 +0200)
Change-Id: I8eed3fdc79ce72521a9db26d527c73a106fdd08f
(cherry picked from commit 878770990beb5641ad70a4f669fd263e891dd1bb)

moonclient/moonclient/tests/tests_empty_policy_new_user.json
moonclient/moonclient/tests/tests_empty_policy_nova.json
moonclient/moonclient/tests/tests_external_commands.json
tests/run_tests.py

index d2ca0e2..1b17cc2 100644 (file)
         "result": "",
         "description": "Upload the Cirros image in glance"
       },
+      {
+        "name": "create secgroup",
+        "external_command": "nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0",
+        "result": "",
+        "description": "Create a new secgroup in Nova"
+      },
+      {
+        "name": "create secgroup",
+        "external_command": "nova secgroup-add-rule default tcp 22 22 0.0.0.0/0",
+        "result": "",
+        "description": "Create a new secgroup in Nova"
+      },
+      {
+        "name": "create router",
+        "external_command": "neutron router-create demo-router",
+        "result": "",
+        "description": "Create a new router"
+      },
+      {
+        "name": "set router",
+        "external_command": "neutron router-gateway-set demo-router ext-net",
+        "result": "",
+        "description": "Configure the new router"
+      },
+      {
+        "name": "set router",
+        "external_command": "neutron net-create demo-net",
+        "result": "",
+        "description": "Configure the new router"
+      },
+      {
+        "name": "set router",
+        "external_command": "neutron subnet-create demo-net 192.168.1.0/24 --name demo-subnet --gateway 192.168.1.1",
+        "result": "",
+        "description": "Configure the new router"
+      },
+      {
+        "name": "set router",
+        "external_command": "neutron router-interface-add demo-router demo-subnet",
+        "result": "",
+        "description": "Configure the new router"
+      },
       {
         "name": "openstack image list",
         "external_command": "nova image-list",
@@ -30,8 +72,8 @@
       {
         "name": "create tenant test",
         "external_command": "openstack project create test_moonclient",
-        "result": "(?P<uuid_image>[\\w-]+)\\s+\\| cirros",
-        "description": "Get an Image ID"
+        "result": "",
+        "description": "Create a new tenant"
       },
       {
         "name": "add role admin to demo",
       {
         "name": "neutron net-list",
         "external_command": "neutron net-list",
-        "result": "(?P<uuid_net>[\\w-]+)\\s+\\| ext-net",
+        "result": "(?P<uuid_net>[\\w-]+)\\s+\\| demo-net",
         "description": "Get an Net ID"
       },
       {
         "name": "nova boot new server",
-        "external_command": "nova boot  --flavor m1.tiny --image $uuid_image --nic net-id=$uuid_net test_moonclient",
-        "result": "(?P<uuid_image>[\\w-]+)\\s+\\| cirros-0.",
+        "external_command": "nova boot  --flavor m1.tiny --image $uuid_image --nic net-id=$uuid_net --security-group default test_moonclient",
+        "result": "",
         "description": "Get an Image ID"
       },
       {
index de266d3..399710b 100644 (file)
         "result": "",
         "description": "Upload the Cirros image in glance"
       },
+      {
+        "name": "create secgroup",
+        "external_command": "nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0",
+        "result": "",
+        "description": "Create a new secgroup in Nova"
+      },
+      {
+        "name": "create secgroup",
+        "external_command": "nova secgroup-add-rule default tcp 22 22 0.0.0.0/0",
+        "result": "",
+        "description": "Create a new secgroup in Nova"
+      },
+      {
+        "name": "create router",
+        "external_command": "neutron router-create demo-router",
+        "result": "",
+        "description": "Create a new router"
+      },
+      {
+        "name": "set router",
+        "external_command": "neutron router-gateway-set demo-router ext-net",
+        "result": "",
+        "description": "Configure the new router"
+      },
+      {
+        "name": "set router",
+        "external_command": "neutron net-create demo-net",
+        "result": "",
+        "description": "Configure the new router"
+      },
+      {
+        "name": "set router",
+        "external_command": "neutron subnet-create demo-net 192.168.1.0/24 --name demo-subnet --gateway 192.168.1.1",
+        "result": "",
+        "description": "Configure the new router"
+      },
+      {
+        "name": "set router",
+        "external_command": "neutron router-interface-add demo-router demo-subnet",
+        "result": "",
+        "description": "Configure the new router"
+      },
       {
         "name": "nova image-list",
         "external_command": "nova image-list",
@@ -33,8 +75,8 @@
       },
       {
         "name": "nova boot new server",
-        "external_command": "nova boot  --flavor m1.tiny --image $uuid_image --nic net-id=$uuid_net test_moonclient",
-        "result": "(?P<uuid_image>[\\w-]+)\\s+\\| cirros",
+        "external_command": "nova boot  --flavor m1.tiny --image $uuid_image --nic net-id=$uuid_net --security-group default test_moonclient",
+        "result": "",
         "description": "Get an Image ID"
       },
       {
index 25993dd..4caa0df 100644 (file)
         "result": "",
         "description": "Upload the Cirros image in glance"
       },
+      {
+        "name": "create secgroup",
+        "external_command": "nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0",
+        "result": "",
+        "description": "Create a new secgroup in Nova"
+      },
+      {
+        "name": "create secgroup",
+        "external_command": "nova secgroup-add-rule default tcp 22 22 0.0.0.0/0",
+        "result": "",
+        "description": "Create a new secgroup in Nova"
+      },
+      {
+        "name": "create router",
+        "external_command": "neutron router-create demo-router",
+        "result": "",
+        "description": "Create a new router"
+      },
+      {
+        "name": "set router",
+        "external_command": "neutron router-gateway-set demo-router ext-net",
+        "result": "",
+        "description": "Configure the new router"
+      },
+      {
+        "name": "set router",
+        "external_command": "neutron net-create demo-net",
+        "result": "",
+        "description": "Configure the new router"
+      },
+      {
+        "name": "set router",
+        "external_command": "neutron subnet-create demo-net 192.168.1.0/24 --name demo-subnet --gateway 192.168.1.1",
+        "result": "",
+        "description": "Configure the new router"
+      },
+      {
+        "name": "set router",
+        "external_command": "neutron router-interface-add demo-router demo-subnet",
+        "result": "",
+        "description": "Configure the new router"
+      },
       {
         "name": "nova image-list",
         "external_command": "nova image-list",
       },
       {
         "name": "nova boot new server",
-        "external_command": "nova boot  --flavor m1.tiny --image $uuid_image --nic net-id=$uuid_net test_moonclient",
-        "result": "(?P<uuid_image>[\\w-]+)\\s+\\| cirros",
+        "external_command": "nova boot  --flavor m1.tiny --image $uuid_image --nic net-id=$uuid_net --security-group default test_moonclient",
+        "result": "",
         "description": "Get an Image ID"
       },
       {
index 2ed011b..4b70219 100755 (executable)
@@ -13,7 +13,12 @@ import os
 import sys
 import time
 import yaml
-
+import subprocess
+import json
+try:
+    import http.client as client
+except ImportError:
+    import httplib as client
 
 PORT_ODL = 8181
 HOST_ODL = "localhost"
@@ -43,26 +48,42 @@ except ImportError:
     from urllib2 import HTTPBasicAuthHandler, build_opener, install_opener
 
 
+def __get_keystone_url():
+    with subprocess.Popen(["openstack", "endpoint", "show", "keystone", "-f", "yaml"], stdout=subprocess.PIPE) as proc:
+        y = yaml.load(proc.stdout.read())
+        url = y['publicurl']
+        url = url.replace("http://", "")
+        url = url.replace("https://", "")
+        host, port = url.split(":", maxsplit=1)
+        port = port.split("/")[0]
+        return host, port
+
+
 def test_federation():
     # Retrieve Moon token
-    url = urlopen('http://{host}:{port}/moon/token'.format(host=HOST_ODL, port=PORT_ODL),
-                  data='grant_type=password&username=admin&password=console'.encode('utf-8'))
-    code = url.getcode()
-    if code not in (200, 201, 202, 204):
-        return False, "Not able to retrieve Moon token (error code: {}).".format(code)
+    khost, kport = __get_keystone_url()
+    auth_data = {'username': 'admin', 'password': 'console'}
+    conn = client.HTTPConnection(khost, kport)
+    headers = {"Content-type": "application/json"}
+    conn.request("POST", "/moon/auth/tokens", json.dumps(auth_data).encode('utf-8'), headers=headers)
+    resp = conn.getresponse()
+    if resp.status not in (200, 201, 202, 204):
+        return False, "Not able to retrieve Moon token on {}:{} (error code: {}).".format(khost, kport, resp.status)
+
 
     # Retrieve ODL token
-    auth_handler = HTTPBasicAuthHandler()
-    auth_handler.add_password(realm='Moon',
-                              uri='http://{host}:{port}/auth/v1/domains'.format(host=HOST_ODL, port=PORT_ODL),
-                              user='admin',
-                              passwd='console')
-    opener = build_opener(auth_handler)
-    install_opener(opener)
-    url = urlopen('http://{host}:{port}/auth/v1/domains'.format(host=HOST_ODL, port=PORT_ODL))
-    code = url.getcode()
-    if code not in (200, 201, 202, 204):
-        return False, "Not able to retrieve ODL token (error code: {}).".format(code)
+    # TODO (asteroide): must found how to get ODL host and port
+    # auth_handler = HTTPBasicAuthHandler()
+    # auth_handler.add_password(realm='Moon',
+    #                           uri='http://{host}:{port}/auth/v1/domains'.format(host=HOST_ODL, port=PORT_ODL),
+    #                           user='admin',
+    #                           passwd='console')
+    # opener = build_opener(auth_handler)
+    # install_opener(opener)
+    # url = urlopen('http://{host}:{port}/auth/v1/domains'.format(host=HOST_ODL, port=PORT_ODL))
+    # code = url.getcode()
+    # if code not in (200, 201, 202, 204):
+    #     return False, "Not able to retrieve ODL token (error code: {}).".format(code)
     return True, ""