diff --git a/package/cloudshell/cp/openstack/domain/services/nova/nova_instance_service.py b/package/cloudshell/cp/openstack/domain/services/nova/nova_instance_service.py index 32b6c1e..57e982d 100644 --- a/package/cloudshell/cp/openstack/domain/services/nova/nova_instance_service.py +++ b/package/cloudshell/cp/openstack/domain/services/nova/nova_instance_service.py @@ -9,7 +9,7 @@ from cloudshell.cp.openstack.common.driver_helper import CloudshellDriverHelper from cloudshell.cp.openstack.models.exceptions import * -from cloudshell.cp.openstack.domain.services.nova.udev_rules import udev_rules_str +from cloudshell.cp.openstack.domain.services.nova.udev_rules import udev_rules_sh_str class NovaInstanceService(object): @@ -69,7 +69,7 @@ def create_instance(self, openstack_session, name, reservation, # user data if deploy_req_model.auto_udev: - server_create_args.update({'userdata':udev_rules_str}) + server_create_args.update({'userdata':udev_rules_sh_str}) instance = client.servers.create(**server_create_args) diff --git a/package/cloudshell/cp/openstack/domain/services/nova/udev_rules.py b/package/cloudshell/cp/openstack/domain/services/nova/udev_rules.py index d5200be..04a8d1c 100644 --- a/package/cloudshell/cp/openstack/domain/services/nova/udev_rules.py +++ b/package/cloudshell/cp/openstack/domain/services/nova/udev_rules.py @@ -1,35 +1,44 @@ -udev_rules_str = \ -'''#!/usr/bin/env python +udev_rules_sh_str = '''#!/bin/sh -import sys -import os +PYTHON= +if [ -e '/usr/bin/python' ]; then + PYTHON=/usr/bin/python +elif [ -e '/usr/bin/python3' ]; then + PYTHON=/usr/bin/python3 +fi -NETDEV_RULES_FILE = "/etc/udev/rules.d/70-attach-interface-qs-cloudshell.rules" +OS_TYPE=`$PYTHON -c 'import sys;print(sys.platform)'` -if sys.platform.lower().find("linux") < 0: - print "Non Linux OS. Doing Nothing..." - sys.exit(0) +LOGGER_TAG="ADD_QS_TAG" +if [ $OS_TYPE != 'linux2' -a $OS_TYPE != 'linux' ]; then + logger -i -s --tag ${LOGGER_TAG} "Platform $OS_TYPE is not supported for Udev rules." + exit 1 +fi -def generate_udev_rules_str(): - if not os.path.exists("/sbin/ifconfig"): - print "Ifconfig does not exist. Doing nothing..." - sys.exit(0) +QS_UDEV_FILE='/etc/udev/rules.d/70-a-qs-connectivity.rules' - if not os.path.exists("/sbin/dhclient"): - print "dhclient does not exist or not in standard path. Doing Noting." - sys.exit(0) +logger -i -s --tag ${LOGGER_TAG} "Creating UDEV Entries in file $QS_UDEV_FILE" +cat < $QS_UDEV_FILE +# Udev Rules for Quali Systems Apply Connectivity - etc_net_file_str = '\\n'.join(['KERNEL=="eth0", GOTO="no_eth0_config"', 'SUBSYSTEM=="net", ACTION=="add", KERNEL=="eth*", RUN+="/sbin/ifconfig %k up", RUN+="/sbin/dhclient -v %k -lf /var/run/dhclient--%.lease -pf /var/run/dhclient--%k.pid"', '', 'LABEL="no_eth0_config"', '']) +# KERNEL=="eth0", GOTO="no_eth0_config" - print etc_net_file_str - with open(NETDEV_RULES_FILE, "w") as f: - f.write(etc_net_file_str) +SUBSYSTEM=="net", ACTION=="add", KERNEL=="eth*", RUN+="/sbin/ifconfig %k up", RUN+="/sbin/dhclient -v %k -lf /var/run/dhclient-qs-%k.lease -pf /var/run/dhclient-qs-%k.pid"' +SUBSYSTEM=="net", ACTION=="add", KERNEL=="en*", RUN+="/sbin/ifconfig %k up", RUN+="/sbin/dhclient -v %k -lf /var/run/dhclient-qs-%k.lease -pf /var/run/dhclient-qs-%k.pid"' - result = os.system("udevadm control --reload") +# LABEL="no_eth0_config" - print result +TOEND + +# We are going to stop renaming of the devices - this messes things up. Everything will be eth0->ethN +logger -i -s --tag $LOGGER_TAG "Disabling device name change." +/bin/ln -s /dev/null /etc/udev/rules.d/80-net-name-slot.rules +/bin/ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules + + +logger -i -s --tag $LOGGER_TAG "Calling udevadm control" +/sbin/udevadm control --reload && /sbin/udevadm trigger --subsystem-match=net -generate_udev_rules_str() ''' \ No newline at end of file diff --git a/package/tests/test_cp/test_openstack/test_domain/test_services/test_nova/test_nova_instance_service.py b/package/tests/test_cp/test_openstack/test_domain/test_services/test_nova/test_nova_instance_service.py index 6fd1227..600d7ff 100644 --- a/package/tests/test_cp/test_openstack/test_domain/test_services/test_nova/test_nova_instance_service.py +++ b/package/tests/test_cp/test_openstack/test_domain/test_services/test_nova/test_nova_instance_service.py @@ -45,7 +45,7 @@ def test_instance_create_success(self): mock_deploy_req_model.affinity_group_uuid = '' mock_deploy_req_model.cp_avail_zone = 'test-avail-zone' - test_nova_instance_service.udev_rules_str = 'test_userdata' + test_nova_instance_service.udev_rules_sh_str = 'test_userdata' mock_cp_resource_model = Mock() mock_cp_resource_model.qs_mgmt_os_net_uuid = '1234'