diff --git a/IM/InfrastructureManager.py b/IM/InfrastructureManager.py index ecb83dcbb..de4725960 100644 --- a/IM/InfrastructureManager.py +++ b/IM/InfrastructureManager.py @@ -1221,10 +1221,12 @@ def check_auth_data(auth): # First check if an OIDC token is included if "token" in im_auth[0]: InfrastructureManager.check_oidc_token(im_auth[0]) - else: + elif "username" in im_auth[0]: if im_auth[0]['username'].startswith(IM.InfrastructureInfo.InfrastructureInfo.OPENID_USER_PREFIX): # This is a OpenID user do not enable to get data using user/pass creds raise IncorrectVMCrecentialsException("Invalid username used for the InfrastructureManager.") + else: + raise IncorrectVMCrecentialsException("No username nor token for the InfrastructureManager.") # Now check if the user is in authorized if not InfrastructureManager.check_im_user(im_auth): diff --git a/IM/VirtualMachine.py b/IM/VirtualMachine.py index dd6efa674..f81625f05 100644 --- a/IM/VirtualMachine.py +++ b/IM/VirtualMachine.py @@ -581,13 +581,13 @@ def setIps(self, public_ips, private_ips, remove_old=False): if real_public_ips: vm_system.setValue('net_interface.%s.connection' % num_net, public_net.id) if len(real_public_ips) > 1: - self.logger.warn("Node with more that one public IP!") - self.logger.debug(real_public_ips) + self.log_warn("Node with more that one public IP!") + self.log_debug(real_public_ips) if len(real_public_ips) == 2: ip1 = IPAddress(real_public_ips[0]) ip2 = IPAddress(real_public_ips[1]) if ip1.version != ip2.version: - self.logger.info("It seems that there are one IPv4 and other IPv6. Get the IPv4 one.") + self.log_info("It seems that there are one IPv4 and other IPv6. Get the IPv4 one.") if ip1.version == 4: vm_system.setValue('net_interface.%s.ip' % num_net, str(real_public_ips[0])) vm_system.setValue('net_interface.%s.ipv6' % num_net, str(real_public_ips[1])) @@ -595,10 +595,10 @@ def setIps(self, public_ips, private_ips, remove_old=False): vm_system.setValue('net_interface.%s.ip' % num_net, str(real_public_ips[1])) vm_system.setValue('net_interface.%s.ipv6' % num_net, str(real_public_ips[0])) else: - self.logger.info("It seems that both are from the same version first one will be used") + self.log_info("It seems that both are from the same version first one will be used") vm_system.setValue('net_interface.%s.ip' % num_net, str(real_public_ips[0])) else: - self.logger.info("It seems that there are more that 2 last ones will be used") + self.log_info("It seems that there are more that 2 last ones will be used") for ip in real_public_ips: if IPAddress(ip).version == 4: vm_system.setValue('net_interface.%s.ip' % num_net, str(ip)) @@ -606,7 +606,11 @@ def setIps(self, public_ips, private_ips, remove_old=False): vm_system.setValue('net_interface.%s.ipv6' % num_net, str(ip)) else: # The usual case - vm_system.setValue('net_interface.%s.ip' % num_net, str(real_public_ips[0])) + if IPAddress(real_public_ips[0]).version == 6: + self.log_warn("Node only with one IPv6!!") + vm_system.setValue('net_interface.%s.ipv6' % num_net, str(real_public_ips[0])) + else: + vm_system.setValue('net_interface.%s.ip' % num_net, str(real_public_ips[0])) if private_ips: private_net_map = {} @@ -664,7 +668,10 @@ def setIps(self, public_ips, private_ips, remove_old=False): # this VM num_net = self.getNumNetworkIfaces() - vm_system.setValue('net_interface.%s.ip' % num_net, str(private_ip)) + if IPAddress(private_ip).version == 6: + vm_system.setValue('net_interface.%s.ipv6' % num_net, str(private_ip)) + else: + vm_system.setValue('net_interface.%s.ip' % num_net, str(private_ip)) vm_system.setValue('net_interface.%s.connection' % num_net, private_net.id) def get_ssh(self, retry=False): diff --git a/IM/__init__.py b/IM/__init__.py index fae67446d..7ddfe83e0 100644 --- a/IM/__init__.py +++ b/IM/__init__.py @@ -19,5 +19,5 @@ 'InfrastructureInfo', 'InfrastructureManager', 'recipe', 'request', 'REST', 'retry', 'ServiceRequests', 'SSH', 'SSHRetry', 'timedcall', 'UnixHTTPAdapter', 'uriparse', 'VirtualMachine', 'VMRC', 'xmlobject'] -__version__ = '1.7.0' +__version__ = '1.7.1' __author__ = 'Miguel Caballer' diff --git a/IM/config.py b/IM/config.py index 78654caf0..d47450d00 100644 --- a/IM/config.py +++ b/IM/config.py @@ -103,6 +103,7 @@ class Config: VM_NUM_USE_CTXT_DIST = 30 DELAY_BETWEEN_VM_RETRIES = 5 + config = ConfigParser() config.read([Config.IM_PATH + '/../im.cfg', Config.IM_PATH + '/../etc/im.cfg', '/etc/im/im.cfg']) @@ -128,6 +129,7 @@ class ConfigOpenNebula: IMAGE_UNAME = '' TTS_URL = 'https://localhost:8443' + if config.has_section("OpenNebula"): parse_options(config, 'OpenNebula', ConfigOpenNebula) diff --git a/IM/connectors/Azure.py b/IM/connectors/Azure.py index 6c05e3b46..4bf007f1e 100644 --- a/IM/connectors/Azure.py +++ b/IM/connectors/Azure.py @@ -66,12 +66,12 @@ class AzureCloudConnector(CloudConnector): } POWER_STATE_MAP = { - 'Deallocated': VirtualMachine.OFF, - 'Deallocating': VirtualMachine.OFF, - 'Running': VirtualMachine.RUNNING, - 'Starting': VirtualMachine.PENDING, - 'Started': VirtualMachine.PENDING, - 'Stopped': VirtualMachine.STOPPED + 'PowerState/deallocated': VirtualMachine.OFF, + 'PowerState/deallocating': VirtualMachine.OFF, + 'PowerState/running': VirtualMachine.RUNNING, + 'PowerState/starting': VirtualMachine.PENDING, + 'PowerState/started': VirtualMachine.PENDING, + 'PowerState/stopped': VirtualMachine.STOPPED } def __init__(self, cloud_info, inf): @@ -645,14 +645,26 @@ def updateVMInfo(self, vm, auth_data): credentials, subscription_id = self.get_credentials(auth_data) compute_client = ComputeManagementClient(credentials, subscription_id) # Get one the virtual machine by name - virtual_machine = compute_client.virtual_machines.get(group_name, vm_name) + virtual_machine = compute_client.virtual_machines.get(group_name, vm_name, expand='instanceView') except Exception as ex: + self.log_warn("The VM does not exists.") + # check if the RG still exists + if self.get_rg(group_name, credentials, subscription_id): + self.log_info("But the RG %s does exits. Return OFF." % group_name) + vm.state = VirtualMachine.OFF + return (True, vm) + self.log_exception("Error getting the VM info: " + vm.id) return (False, "Error getting the VM info: " + vm.id + ". " + str(ex)) self.log_info("VM info: " + vm.id + " obtained.") vm.state = self.PROVISION_STATE_MAP.get(virtual_machine.provisioning_state, VirtualMachine.UNKNOWN) - self.log_info("The VM state is: " + vm.state) + + if (vm.state == VirtualMachine.RUNNING and virtual_machine.instance_view and + len(virtual_machine.instance_view.statuses) > 1): + vm.state = self.POWER_STATE_MAP.get(virtual_machine.instance_view.statuses[1].code, VirtualMachine.UNKNOWN) + + self.log_debug("The VM state is: " + vm.state) instance_type = self.get_instance_type_by_name(virtual_machine.hardware_profile.vm_size, virtual_machine.location, credentials, subscription_id) diff --git a/IM/connectors/EC2.py b/IM/connectors/EC2.py index 5059c68e3..2f3e3d09e 100644 --- a/IM/connectors/EC2.py +++ b/IM/connectors/EC2.py @@ -1009,10 +1009,8 @@ def setIPsFromInstance(self, vm, instance): # It will be used if it is different to the public IP of the # instance if str(address.public_ip) != instance.ip_address: - vm_system.setValue( - 'net_interface.' + str(num_nets) + '.ip', str(instance.ip_address)) - vm_system.setValue( - 'net_interface.' + str(num_nets) + '.connection', public_net.id) + vm_system.setValue('net_interface.' + str(num_nets) + '.ip', str(instance.ip_address)) + vm_system.setValue('net_interface.' + str(num_nets) + '.connection', public_net.id) num_pub_nets += 1 num_nets += 1 @@ -1020,8 +1018,7 @@ def setIPsFromInstance(self, vm, instance): n = 0 requested_ips = [] while vm.getRequestedSystem().getValue("net_interface." + str(n) + ".connection"): - net_conn = vm.getRequestedSystem().getValue( - 'net_interface.' + str(n) + '.connection') + net_conn = vm.getRequestedSystem().getValue('net_interface.' + str(n) + '.connection') if vm.info.get_network_by_id(net_conn).isPublic(): fixed_ip = vm.getRequestedSystem().getValue("net_interface." + str(n) + ".ip") requested_ips.append(fixed_ip) diff --git a/IM/connectors/OpenNebula.py b/IM/connectors/OpenNebula.py index acdabbbd6..94d203c48 100644 --- a/IM/connectors/OpenNebula.py +++ b/IM/connectors/OpenNebula.py @@ -286,7 +286,11 @@ def setIPsFromTemplate(self, vm, template): net = vm.info.get_network_by_id(net_name) provider_id = net.getValue("provider_id") if provider_id == nic.NETWORK: - system.setValue("net_interface." + str(i) + ".ip", str(nic.IP)) + ip = str(nic.IP) + if IPAddress(ip).version == 6: + system.setValue("net_interface." + str(i) + ".ipv6", ip) + else: + system.setValue("net_interface." + str(i) + ".ip", ip) break i += 1 diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index 368d59bf2..5517d3781 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -289,26 +289,41 @@ def map_radl_ost_networks(self, radl_nets, ost_nets): if net_name: for radl_net in radl_nets: net_provider_id = radl_net.getValue('provider_id') + if net_provider_id: + parts = net_provider_id.split(".") + if len(parts) > 1: + net_provider_id = parts[0] if net_name == net_provider_id: - res[radl_net.id] = ip - break + if radl_net.isPublic() == is_public: + res[radl_net.id] = ip + break + else: + # the ip not matches the is_public value + res["#UNMAPPED#"].append(ip) else: if radl_net.id not in res: if radl_net.isPublic() == is_public: res[radl_net.id] = ip radl_net.setValue('provider_id', net_name) + if ip in res["#UNMAPPED#"]: + res["#UNMAPPED#"].remove(ip) break else: # the ip not matches the is_public value res["#UNMAPPED#"].append(ip) else: # It seems to be a floating IP + added = False for radl_net in radl_nets: if radl_net.id not in res and radl_net.isPublic() == is_public: res[radl_net.id] = ip + added = True break + if not added: + res["#UNMAPPED#"].append(ip) + return res def get_node_floating_ips(self, node): @@ -366,7 +381,10 @@ def setIPsFromInstance(self, vm, node): net_name = system.getValue("net_interface." + str(i) + ".connection") if net_name in map_nets: ip = map_nets[net_name] - system.setValue("net_interface." + str(i) + ".ip", ip) + if IPAddress(ip).version == 6: + system.setValue("net_interface." + str(i) + ".ipv6", ip) + else: + system.setValue("net_interface." + str(i) + ".ip", ip) ips_assigned.append(ip) i += 1 @@ -377,7 +395,10 @@ def setIPsFromInstance(self, vm, node): if net_name != '#UNMAPPED#': if ip not in ips_assigned: num_net = system.getNumNetworkIfaces() - system.setValue('net_interface.' + str(num_net) + '.ip', ip) + if IPAddress(ip).version == 6: + system.setValue('net_interface.' + str(num_net) + '.ipv6', ip) + else: + system.setValue('net_interface.' + str(num_net) + '.ip', ip) system.setValue('net_interface.' + str(num_net) + '.connection', net_name) else: pub_ips = [] @@ -445,6 +466,10 @@ def get_networks(self, driver, radl): else: # First check if the user has specified a provider ID if net_provider_id: + parts = net_provider_id.split(".") + if len(parts) > 1: + net_provider_id = parts[0] + for net in ost_nets: if net.name == net_provider_id: if net.name not in used_nets: @@ -624,6 +649,14 @@ def manage_elastic_ips(self, vm, node, public_ips): if net.isPublic(): fixed_ip = vm.getRequestedSystem().getValue("net_interface." + str(n) + ".ip") pool_name = net.getValue("pool_name") + + if not pool_name: + net_provider_id = net.getValue("provider_id") + if net_provider_id: + parts = net_provider_id.split(".") + if len(parts) > 1: + pool_name = parts[1] + requested_ips.append((fixed_ip, pool_name)) n += 1 @@ -860,7 +893,7 @@ def finalize(self, vm, last, auth_data): return (True, "") - def delete_security_groups(self, driver, inf, timeout=90, delay=10): + def delete_security_groups(self, driver, inf, timeout=180, delay=10): """ Delete the SG of this inf """ diff --git a/IM/db.py b/IM/db.py index ac98b3142..dcb8a0113 100644 --- a/IM/db.py +++ b/IM/db.py @@ -227,6 +227,7 @@ def table_exists(self, table_name): else: return True + try: class IntegrityError(sqlite.IntegrityError): """ Class to return IntegrityError independently of the DB used""" diff --git a/IM/request.py b/IM/request.py index f6421b243..7bf4a507b 100644 --- a/IM/request.py +++ b/IM/request.py @@ -280,6 +280,7 @@ def serve_forever_in_thread(self): self.__thread.daemon = True self.__thread.start() + if Config.XMLRCP_SSL: class AsyncSSLXMLRPCServer(ThreadingMixIn, SSLSimpleXMLRPCServer): diff --git a/changelog b/changelog index 2ebed6ca0..c52b958fe 100644 --- a/changelog +++ b/changelog @@ -407,3 +407,8 @@ IM 1.7.0 * Change in the DB schema in the case of MySQL DB. This command must be made in the current DB: ALTER TABLE `inf_list` ADD COLUMN `rowid` INT AUTO_INCREMENT UNIQUE FIRST; + +IM 1.7.1: + * Fix problems with nodes with IPv6 in OpenStack conn. + * Fix Azure conn does not get the correct state (in case of suspended VMs). + * Enable to specify pool_name in the network provider_ip in OpenStack conn. diff --git a/contextualization/conf-ansible.yml b/contextualization/conf-ansible.yml index 01f9251ba..dab7eac41 100644 --- a/contextualization/conf-ansible.yml +++ b/contextualization/conf-ansible.yml @@ -158,11 +158,11 @@ when: (ansible_os_family == "RedHat" and ansible_distribution_major_version|int < 6) or (ansible_os_family == "Suse" and ansible_distribution_major_version|int < 10) - name: Change ssh_args to set ControlPersist to 15 min in ansible.cfg - ini_file: dest=/etc/ansible/ansible.cfg section=ssh_connection option=ssh_args value="-o ControlMaster=auto -o ControlPersist=900s" + ini_file: dest=/etc/ansible/ansible.cfg section=ssh_connection option=ssh_args value="-o ControlMaster=auto -o ControlPersist=900s -o UserKnownHostsFile=/dev/null" when: ansible_os_family == "Debian" or (ansible_os_family == "RedHat" and ansible_distribution_major_version|int >= 7) or (ansible_os_family == "Suse" and ansible_distribution_major_version|int >= 12) - name: Change ssh_args to remove ControlPersist in REL 6 and older in ansible.cfg - ini_file: dest=/etc/ansible/ansible.cfg section=ssh_connection option=ssh_args value="" + ini_file: dest=/etc/ansible/ansible.cfg section=ssh_connection option=ssh_args value="-o UserKnownHostsFile=/dev/null" when: (ansible_os_family == "RedHat" and ansible_distribution_major_version|int < 7) or (ansible_os_family == "Suse" and ansible_distribution_major_version|int < 12) - name: Activate SSH pipelining in ansible.cfg diff --git a/contextualization/ctxt_agent.py b/contextualization/ctxt_agent.py index 89de58edf..a8877d372 100644 --- a/contextualization/ctxt_agent.py +++ b/contextualization/ctxt_agent.py @@ -630,6 +630,7 @@ def run(general_conf_file, vm_conf_file): return res_data['OK'] + if __name__ == "__main__": parser = argparse.ArgumentParser(description='Contextualization Agent.') parser.add_argument('general', type=str, nargs=1) diff --git a/contextualization/ctxt_agent_dist.py b/contextualization/ctxt_agent_dist.py index b5635ea72..4ff3fe390 100755 --- a/contextualization/ctxt_agent_dist.py +++ b/contextualization/ctxt_agent_dist.py @@ -960,6 +960,7 @@ def run(general_conf_file, vm_conf_file, local): return res_data['OK'] + if __name__ == "__main__": parser = argparse.ArgumentParser(description='Contextualization Agent.') parser.add_argument('general', type=str, nargs=1) diff --git a/doc/source/client.rst b/doc/source/client.rst index 2d903d50e..8a00d47ef 100644 --- a/doc/source/client.rst +++ b/doc/source/client.rst @@ -46,9 +46,11 @@ The :program:`im_client` is called like this:: ``list`` List the infrastructure IDs created by the user. - ``create radlfile`` + ``create radlfile async_flag`` Create an infrastructure using RADL specified in the file with path - ``radlfile``. + ``radlfile``. The ``async_flag`` parameter is optional + and is a flag to specify if the creation call will wait the resources + to be created or return immediately the id of the infrastructure. ``destroy infId`` Destroy the infrastructure with ID ``infId``. diff --git a/doc/source/web.rst b/doc/source/web.rst index b5506a753..4923a40af 100644 --- a/doc/source/web.rst +++ b/doc/source/web.rst @@ -16,6 +16,16 @@ Configuration The web interface reads the configuration from :file:`$IM_WEB_PATH/config.php`. It has the following variables: +.. confval:: im_use_rest + + Flag to set the usage of the REST API instead of the XML-RPC one. + The default value is `false`. + +.. confval:: im_use_ssl + + Flag to set the usage of the APIs using HTTPS protocol instead of the standard HTTP. + The default value is `false`. + .. confval:: im_host Hostname or IP address of the host with the IM service. @@ -36,6 +46,26 @@ the following variables: Location of the IM service recipes D.B. To use that feature the IM recipes file must accesible to the web server The default value is `""`. +.. confval:: openid_issuer + + OpenID Issuer supported use "" to disable OpenID support. + The default value is `""`. + +.. confval:: openid_name + + OpenID Issuer name. + The default value is `""`. + +.. confval:: CLIENT_ID + + OpenID Client data. + The default value is `""`. + +.. confval:: CLIENT_SECRET + + OpenID Client data. + The default value is `""`. + Docker Image ------------ @@ -47,7 +77,7 @@ This container is prepaired to work linked with the IM service container `grycap * First launch the IM service specifying the name "im": ```sh -sudo docker run -d -p 8899:8899 --name im grycap/im +sudo docker run -d -p 8899:8899 -p 8800:8800 --name im grycap/im ```` * Then launch the im-web container linking to the im: diff --git a/docker-devel/Dockerfile b/docker-devel/Dockerfile index 3c5b15358..3951ffd54 100644 --- a/docker-devel/Dockerfile +++ b/docker-devel/Dockerfile @@ -1,7 +1,7 @@ # Dockerfile to create a container with the IM service FROM grycap/jenkins:ubuntu16.04-im MAINTAINER Miguel Caballer -LABEL version="1.7.0" +LABEL version="1.7.1" LABEL description="Container image to run the IM service with TOSCA support. (http://www.grycap.upv.es/im)" # Install tosca-parser diff --git a/docker-py3/Dockerfile b/docker-py3/Dockerfile index 758576331..7599a6f0c 100644 --- a/docker-py3/Dockerfile +++ b/docker-py3/Dockerfile @@ -1,7 +1,7 @@ # Dockerfile to create a container with the IM service FROM ubuntu:16.04 LABEL maintainer="Miguel Caballer " -LABEL version="1.6.4" +LABEL version="1.7.1" LABEL description="Container image to run the IM service. (http://www.grycap.upv.es/im)" EXPOSE 8899 8800 @@ -16,11 +16,14 @@ RUN pip3 install msrest msrestazure azure-common azure-mgmt-storage azure-mgmt-c # Install IM RUN apt-get update && apt-get install --no-install-recommends -y gcc libssl-dev libffi-dev libsqlite3-dev && \ - pip3 install IM==1.6.4 && \ + pip3 install IM==1.6.1 && \ apt-get remove -y gcc libssl-dev libffi-dev libsqlite3-dev python-dev python-pip && \ apt-get autoremove -y && \ rm -rf /var/lib/apt/lists/* +# Force requests to be version 2.11.1 to avoid SSL ca errors with proxy files +RUN pip3 install requests==2.11.1 + # Copy a ansible.cfg with correct minimum values COPY ansible.cfg /etc/ansible/ansible.cfg diff --git a/docker/Dockerfile b/docker/Dockerfile index 2a06816ad..17cfa8b5b 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,7 +1,7 @@ # Dockerfile to create a container with the IM service and TOSCA support FROM ubuntu:16.04 MAINTAINER Miguel Caballer -LABEL version="1.7.0" +LABEL version="1.7.1" LABEL description="Container image to run the IM service with TOSCA support. (http://www.grycap.upv.es/im)" # Install Ansible @@ -23,7 +23,7 @@ RUN wget https://launchpad.net/ubuntu/+archive/primary/+files/python-msrest_0.4. # Install IM RUN wget https://github.com/grycap/RADL/releases/download/v1.1.0/python-radl_1.1.0-1_all.deb && \ - wget https://github.com/indigo-dc/im/releases/download/v1.6.8/python-im_1.7.0-1_all.deb && \ + wget https://github.com/indigo-dc/im/releases/download/v1.7.1/python-im_1.7.1-1_all.deb && \ wget https://github.com/indigo-dc/tosca-parser/releases/download/0.9.1/python-tosca-parser_0.9.1-1_all.deb && \ dpkg -i python-radl_*_all.deb ; \ dpkg -i python-tosca-parser_*_all.deb ; \ diff --git a/im_service.py b/im_service.py index c0ed75964..a64566e60 100755 --- a/im_service.py +++ b/im_service.py @@ -373,6 +373,7 @@ def signal_int_handler(signal, frame): """ im_stop() + if __name__ == "__main__": parser = argparse.ArgumentParser(description='IM service') parser.add_argument('--version', help='Show IM service version.', dest="version", diff --git a/scripts/db_1_4_to_1_5.py b/scripts/db_1_4_to_1_5.py index 5b2699486..e83588266 100644 --- a/scripts/db_1_4_to_1_5.py +++ b/scripts/db_1_4_to_1_5.py @@ -105,6 +105,7 @@ def complete_data(): vm.cloud_connector = None vm.inf = None + if __name__ == "__main__": if not Config.DATA_DB: sys.stderr.write("No DATA_DB defined in the im.cfg file!!") diff --git a/scripts/delete_old_infs.py b/scripts/delete_old_infs.py index 16e77d25b..268e1238f 100644 --- a/scripts/delete_old_infs.py +++ b/scripts/delete_old_infs.py @@ -36,6 +36,7 @@ def delete_data_from_db(db_url, date): sys.stderr.write("ERROR connecting with the database!.") sys.exit(-1) + if __name__ == "__main__": if not Config.DATA_DB: sys.stderr.write("No DATA_DB defined in the im.cfg file!!\n") diff --git a/test/functional/test_im.py b/test/functional/test_im.py index 4d35c32ec..11ee3ab34 100755 --- a/test/functional/test_im.py +++ b/test/functional/test_im.py @@ -182,5 +182,6 @@ def test_inf_lifecycle(self): IM.DestroyInfrastructure(infId, auth0) + if __name__ == "__main__": unittest.main() diff --git a/test/integration/QuickTestIM.py b/test/integration/QuickTestIM.py index 3c39df082..cb97e4049 100755 --- a/test/integration/QuickTestIM.py +++ b/test/integration/QuickTestIM.py @@ -541,5 +541,6 @@ def test_75_destroy(self): self.assertTrue( success, msg="ERROR calling DestroyInfrastructure: " + str(res)) + if __name__ == '__main__': unittest.main() diff --git a/test/integration/TestIM.py b/test/integration/TestIM.py index 6d1d94f1e..2f2249a69 100755 --- a/test/integration/TestIM.py +++ b/test/integration/TestIM.py @@ -685,5 +685,6 @@ def test_95_destroy(self): self.assertTrue( success, msg="ERROR calling DestroyInfrastructure: " + str(res)) + if __name__ == '__main__': unittest.main() diff --git a/test/integration/TestREST.py b/test/integration/TestREST.py index b2c9c9714..b7448137d 100755 --- a/test/integration/TestREST.py +++ b/test/integration/TestREST.py @@ -477,5 +477,6 @@ def test_98_destroy(self): self.assertEqual(resp.status_code, 200, msg="ERROR destroying the infrastructure:" + resp.text) + if __name__ == '__main__': unittest.main() diff --git a/test/integration/TestREST_JSON.py b/test/integration/TestREST_JSON.py index e7cd9c7c4..f6bb54494 100755 --- a/test/integration/TestREST_JSON.py +++ b/test/integration/TestREST_JSON.py @@ -201,5 +201,6 @@ def test_95_destroy(self): self.assertEqual(resp.status_code, 200, msg="ERROR destroying the infrastructure:" + resp.text) + if __name__ == '__main__': unittest.main() diff --git a/test/loadtest/LoadTest.py b/test/loadtest/LoadTest.py index 129debdf3..684401f13 100755 --- a/test/loadtest/LoadTest.py +++ b/test/loadtest/LoadTest.py @@ -371,6 +371,7 @@ def test(num_client): now = datetime.datetime.now() print(now, ": End client num: %d" % num_client) + if __name__ == '__main__': MAX_THREADS = 1 MAX_CLIENTS = 1 diff --git a/test/loadtest/LoadTestR.py b/test/loadtest/LoadTestR.py index 00025968c..5567ccd89 100755 --- a/test/loadtest/LoadTestR.py +++ b/test/loadtest/LoadTestR.py @@ -118,6 +118,7 @@ def test(num_client): now = datetime.datetime.now() print(now, ": End client num: %d" % num_client) + if __name__ == '__main__': MAX_THREADS = 1 MAX_CLIENTS = 1 diff --git a/test/loadtest/LoadTestREST.py b/test/loadtest/LoadTestREST.py index d7da5e14e..ba105ea92 100755 --- a/test/loadtest/LoadTestREST.py +++ b/test/loadtest/LoadTestREST.py @@ -330,6 +330,7 @@ def test(num_client): now = datetime.datetime.now() print(now, ": End client num: %d" % num_client) + if __name__ == '__main__': MAX_THREADS = 1 MAX_CLIENTS = 1 diff --git a/test/loadtest/LoadTestRESTR.py b/test/loadtest/LoadTestRESTR.py index d668767df..ae2041c5a 100755 --- a/test/loadtest/LoadTestRESTR.py +++ b/test/loadtest/LoadTestRESTR.py @@ -120,6 +120,7 @@ def test(num_client): now = datetime.datetime.now() print(now, ": End client num: %d" % num_client) + if __name__ == '__main__': MAX_THREADS = 1 MAX_CLIENTS = 1 diff --git a/test/unit/REST.py b/test/unit/REST.py index 585b09df6..a3650da77 100755 --- a/test/unit/REST.py +++ b/test/unit/REST.py @@ -779,5 +779,6 @@ def test_format_output(self, get_media_type): info = format_output(["1", "2"]) self.assertEqual(info, 'Unsupported Accept Media Types: application/zip') + if __name__ == "__main__": unittest.main() diff --git a/test/unit/ServiceRequests.py b/test/unit/ServiceRequests.py index a17935161..ce2c6b283 100755 --- a/test/unit/ServiceRequests.py +++ b/test/unit/ServiceRequests.py @@ -172,5 +172,6 @@ def test_version(self, inflist): req = IM.ServiceRequests.IMBaseRequest.create_request(IM.ServiceRequests.IMBaseRequest.GET_VERSION) req._call_function() + if __name__ == '__main__': unittest.main() diff --git a/test/unit/Tosca.py b/test/unit/Tosca.py index b679acc02..89b8546ca 100755 --- a/test/unit/Tosca.py +++ b/test/unit/Tosca.py @@ -92,5 +92,6 @@ def test_tosca_get_outputs(self): 'token': 'pass', 'user': 'ubuntu'}}) + if __name__ == "__main__": unittest.main() diff --git a/test/unit/VMRC.py b/test/unit/VMRC.py index c37770265..219f0bb86 100755 --- a/test/unit/VMRC.py +++ b/test/unit/VMRC.py @@ -98,5 +98,6 @@ def test_list_vm(self, suds_cli): self.assertEqual(res_radl[0].getValue("disk.0.os.credentials.password"), "pass") self.assertEqual(res_radl[0].getValue("disk.0.os.credentials.username"), "user") + if __name__ == '__main__': unittest.main() diff --git a/test/unit/connectors/Azure.py b/test/unit/connectors/Azure.py index 531bc83fe..260136084 100755 --- a/test/unit/connectors/Azure.py +++ b/test/unit/connectors/Azure.py @@ -252,6 +252,11 @@ def test_30_updateVMInfo(self, credentials, dns_client, compute_client, network_ avm.provisioning_state = "Succeeded" avm.hardware_profile.vm_size = "instance_type1" avm.location = "northeurope" + status1 = MagicMock() + status1.code = "ProvisioningState/succeeded" + status2 = MagicMock() + status2.code = "PowerState/running" + avm.instance_view.statuses = [status1, status2] ni = MagicMock() ni.id = "/subscriptions/subscription-id/resourceGroups/rg0/providers/Microsoft.Network/networkInterfaces/ni-0" avm.network_profile.network_interfaces = [ni] diff --git a/test/unit/connectors/GCE.py b/test/unit/connectors/GCE.py index 169ba302d..d57f4e8cf 100755 --- a/test/unit/connectors/GCE.py +++ b/test/unit/connectors/GCE.py @@ -406,5 +406,6 @@ def test_70_get_custom_instance(self): instance = gce_cloud.get_instance_type(sizes, radl.systems[0]) self.assertEquals(instance.name, "sizenamne") + if __name__ == '__main__': unittest.main() diff --git a/test/unit/connectors/OpenNebula.py b/test/unit/connectors/OpenNebula.py index dbcb45a4d..9c60c8e1d 100755 --- a/test/unit/connectors/OpenNebula.py +++ b/test/unit/connectors/OpenNebula.py @@ -390,5 +390,6 @@ def test_80_delete_image(self, sleep, getONEVersion, server_proxy): self.assertEqual(one_server.one.image.delete.call_args_list[1], call('user:pass', 1)) self.assertNotIn("ERROR", self.log.getvalue(), msg="ERROR found in log: %s" % self.log.getvalue()) + if __name__ == '__main__': unittest.main() diff --git a/test/unit/connectors/OpenStack.py b/test/unit/connectors/OpenStack.py index 277b529b4..21c92c77e 100755 --- a/test/unit/connectors/OpenStack.py +++ b/test/unit/connectors/OpenStack.py @@ -206,7 +206,7 @@ def test_20_launch(self, save_data, get_driver): @patch('libcloud.compute.drivers.openstack.OpenStackNodeDriver') def test_30_updateVMInfo(self, get_driver): radl_data = """ - network net (outbound = 'yes') + network net (outbound = 'yes' and provider_id = 'os-lan.pool1') system test ( cpu.arch='x86_64' and cpu.count=1 and @@ -214,7 +214,7 @@ def test_30_updateVMInfo(self, get_driver): net_interface.0.connection = 'net' and net_interface.0.dns_name = 'test' and disk.0.os.name = 'linux' and - disk.0.image.url = 'one://server.com/1' and + disk.0.image.url = 'ost://server.com/ami-id' and disk.0.os.credentials.username = 'user' and disk.0.os.credentials.password = 'pass' )""" diff --git a/test/unit/db.py b/test/unit/db.py index 29b438c1b..95b411c13 100644 --- a/test/unit/db.py +++ b/test/unit/db.py @@ -62,5 +62,6 @@ def test_db(self, mdb_conn): db.close() + if __name__ == '__main__': unittest.main() diff --git a/test/unit/onetts.py b/test/unit/onetts.py index 7017ead4b..917a50e10 100755 --- a/test/unit/onetts.py +++ b/test/unit/onetts.py @@ -47,5 +47,6 @@ def test_list_providers(self, ttscli): self.assertEqual(username, "username", msg="ERROR: getting one auth from TTS, incorrect username.") self.assertEqual(password, "password", msg="ERROR: getting one auth from TTS, incorrect password.") + if __name__ == '__main__': unittest.main() diff --git a/test/unit/openid.py b/test/unit/openid.py index 70a3061a0..514cf59c1 100755 --- a/test/unit/openid.py +++ b/test/unit/openid.py @@ -74,5 +74,6 @@ def test_get_token_introspection(self, requests): self.assertTrue(success) self.assertEqual(json.loads(token_info), token_info_resp) + if __name__ == '__main__': unittest.main() diff --git a/test/unit/recipe.py b/test/unit/recipe.py index 1957c6afc..ad2f416da 100755 --- a/test/unit/recipe.py +++ b/test/unit/recipe.py @@ -51,5 +51,6 @@ def test_recipe(self, DataBase): self.assertEqual(res[0][1], "mod") self.assertEqual(res[0][2], "gmod") + if __name__ == '__main__': unittest.main() diff --git a/test/unit/test_ansible.py b/test/unit/test_ansible.py index c16125931..f1a575714 100755 --- a/test/unit/test_ansible.py +++ b/test/unit/test_ansible.py @@ -49,5 +49,6 @@ def test_ansible_thread(self): self.assertIn("changed=2", output.getvalue()) print(output.getvalue()) + if __name__ == '__main__': unittest.main() diff --git a/test/unit/test_ctxt_agent.py b/test/unit/test_ctxt_agent.py index 6bcbbf7b0..f3f7e94bc 100755 --- a/test/unit/test_ctxt_agent.py +++ b/test/unit/test_ctxt_agent.py @@ -242,5 +242,6 @@ def test_90_replace_vm_ip(self): data = f.read() self.assertIn(" ansible_host=%s ansible_ssh_host=%s \n" % (vm_data['ctxt_ip'], vm_data['ctxt_ip']), data) + if __name__ == '__main__': unittest.main() diff --git a/test/unit/test_ctxt_agent_dist.py b/test/unit/test_ctxt_agent_dist.py index a8d7103fb..9ed1a9eed 100755 --- a/test/unit/test_ctxt_agent_dist.py +++ b/test/unit/test_ctxt_agent_dist.py @@ -279,5 +279,6 @@ def test_90_replace_vm_ip(self): self.assertIn(" ansible_host=%s \n" % vm_data['ctxt_ip'], data) self.assertIn(" ansible_ssh_host=%s \n" % vm_data['ctxt_ip'], data) + if __name__ == '__main__': unittest.main() diff --git a/test/unit/test_im_logic.py b/test/unit/test_im_logic.py index 8a76bd87f..486136bd7 100755 --- a/test/unit/test_im_logic.py +++ b/test/unit/test_im_logic.py @@ -258,6 +258,13 @@ def test_inf_creation_errors(self): deploy wn 1 """ + # this case raises an exception + auth0 = Authentication([{'type': 'InfrastructureManager', 'password': 'tests'}]) + with self.assertRaises(Exception) as ex: + IM.CreateInfrastructure(radl, auth0) + + self.assertEqual(str(ex.exception), "No username nor token for the InfrastructureManager.") + # this case raises an exception auth0 = Authentication([{'type': 'InfrastructureManager', 'username': 'test', 'password': 'tests'}]) @@ -1203,5 +1210,6 @@ def test_create_async(self): IM.DestroyInfrastructure(infId, auth0) + if __name__ == "__main__": unittest.main() diff --git a/test/unit/timedcall.py b/test/unit/timedcall.py index 74abc2413..dae9b27b0 100755 --- a/test/unit/timedcall.py +++ b/test/unit/timedcall.py @@ -57,5 +57,6 @@ def test_timer(self): time.sleep(0.1) self.assertEqual(res, 4) + if __name__ == '__main__': unittest.main() diff --git a/test/unit/tts.py b/test/unit/tts.py index d71efe58e..57ebe19a1 100755 --- a/test/unit/tts.py +++ b/test/unit/tts.py @@ -108,5 +108,7 @@ def test_request_credential(self, requests): self.assertTrue(success, msg="ERROR: getting credentials: %s." % cred) self.assertEqual(cred, expected_cred, msg="ERROR: getting credentials: Unexpected credetials.") + + if __name__ == '__main__': unittest.main() diff --git a/test/unit/xmlobject.py b/test/unit/xmlobject.py index 126173479..8b05716ce 100755 --- a/test/unit/xmlobject.py +++ b/test/unit/xmlobject.py @@ -78,5 +78,6 @@ def test_timed_call(self): '512\n\n') self.assertEqual(res, expected) + if __name__ == '__main__': unittest.main()