def apply(self, args):
        responses = self.check(args)
        if responses is False:
            self.log.error("Check failed. Not applying")
            self.parent.footer.set_text("Check failed. Not applying.")
            self.log.error("%s" % (responses))
            return False

        self.parent.footer.set_text("Applying changes... (May take up to 20s)")
        puppetclasses = []

        #If there is a gateway configured in /etc/sysconfig/network, unset it
        expr = '^GATEWAY=.*'
        replace.replaceInFile("/etc/sysconfig/network", expr, "")

        l3ifconfig = {'type': "resource",
                      'class': "l23network::l3::ifconfig",
                      'name': self.activeiface}
        if responses["onboot"].lower() == "no":
            params = {"ipaddr": "none",
                      "gateway": ""}
        elif responses["bootproto"] == "dhcp":
            self.unset_gateway()
            if "dhcp_nowait" in responses.keys():
                params = {"ipaddr": "dhcp",
                          "dhcp_nowait": responses["dhcp_nowait"]}
            else:
                params = {"ipaddr": "dhcp"}
        else:
            cidr = network.netmaskToCidr(responses["netmask"])
            params = {"ipaddr": "{0}/{1}".format(responses["ipaddr"], cidr),
                      "check_by_ping": "none"}
            if len(responses["gateway"]) > 1:
                params["gateway"] = responses["gateway"]
                self.unset_gateway()
        l3ifconfig['params'] = params
        puppetclasses.append(l3ifconfig)
        self.log.info("Puppet data: %s" % (puppetclasses))
        try:
            self.parent.refreshScreen()
            puppet.puppetApply(puppetclasses)
            ModuleHelper.getNetwork(self)
            gateway = self.get_default_gateway_linux()
            if gateway is None:
                gateway = ""
            self.fixEtcHosts()

        except Exception as e:
            self.log.error(e)
            self.parent.footer.set_text("Error applying changes. Check logs "
                                        "for details.")
            ModuleHelper.getNetwork(self)
            self.setNetworkDetails()
            return False
        self.parent.footer.set_text("Changes successfully applied.")
        ModuleHelper.getNetwork(self)
        self.setNetworkDetails()

        return True
 def test_incorrect_type(self, m_execute, m_log):
     self.classes.append({
         'type': 'incorrect',
         'name': 'incorrect name',
         'class': 'class_2',
         'params': {}
     })
     self.assertEqual(puppet.puppetApply(self.classes), False)
     self.assertFalse(m_execute.called)
     m_log.error.assert_called_once_with('Invalid type %s', 'incorrect')
 def _update_dnsmasq(self, settings):
     puppet_classes = [{
         "type": "resource",
         "class": "fuel::dnsmasq::dhcp_range",
         "name": "default",
         "params": {
             "dhcp_start_address": settings["dhcp_pool_start"],
             "dhcp_end_address": settings["dhcp_pool_end"],
             "dhcp_netmask": settings["netmask"],
             "dhcp_gateway": settings["dhcp_gateway"],
             "next_server": settings["ipaddress"]
         }
     }]
     log.debug("Start puppet with data {0}".format(puppet_classes))
     return puppet.puppetApply(puppet_classes)
Beispiel #4
0
    def apply(self, args):
        responses = self.check(args)
        if responses is False:
            self.log.error("Check failed. Not applying")
            self.parent.footer.set_text("Check failed. Not applying.")
            self.log.error("%s" % (responses))
            return False

        self.parent.footer.set_text("Applying changes... (May take up to 20s)")

        # Build puppet resources to apply l23network puppet module to enable
        # network changes
        puppetclasses = []

        # FIXME(mattymo): install_bondtool param does not work (LP#1541028)
        # The following 4 lines should be removed when fixed.
        disable_bond = {
            'type': "literal",
            'name': 'K_mod <| title == "bonding" |> {ensure => absent} '}
        puppetclasses.append(disable_bond)

        # If there is a gateway configured in /etc/sysconfig/network, unset it
        expr = '^GATEWAY=.*'
        replace.replaceInFile("/etc/sysconfig/network", expr, "")

        # Initialize l23network class for NetworkManager fixes
        l23network = {'type': "resource",
                      'class': "class",
                      'name': "l23network",
                      'params': {'install_bondtool': False}}
        puppetclasses.append(l23network)

        # Prepare l23network interface configuration
        l3ifconfig = {'type': "resource",
                      'class': "l23network::l3::ifconfig",
                      'name': self.activeiface}

        additionalclasses = []
        if responses["onboot"].lower() == "no":
            params = {"ipaddr": "none",
                      "gateway": ""}
        elif responses["bootproto"] == "dhcp":
            additionalclasses = self.clear_gateways_except(self.activeiface)
            params = {"ipaddr": "dhcp"}
        else:
            cidr = network.addr_in_cidr_notation(responses["ipaddr"],
                                                 responses["netmask"])
            params = {"ipaddr": cidr,
                      "check_by_ping": "none"}
            if len(responses["gateway"]) > 1:
                params["gateway"] = responses["gateway"]
                additionalclasses = self.clear_gateways_except(
                    self.activeiface)

        puppetclasses.extend(additionalclasses)
        l3ifconfig['params'] = params
        puppetclasses.append(l3ifconfig)
        self.log.info("Puppet data: %s" % (puppetclasses))

        try:
            self.parent.refreshScreen()
            result = puppet.puppetApply(puppetclasses)
            if result is False:
                raise Exception("Puppet apply failed")
            ModuleHelper.getNetwork(self)
            gateway = self.get_default_gateway_linux()
            if gateway is None:
                gateway = ""
            self.fixEtcHosts()
            if responses['bootproto'] == 'dhcp':
                self.parent.dns_might_have_changed = True

        except Exception as e:
            self.log.error(e)
            self.parent.footer.set_text("Error applying changes. Check logs "
                                        "for details.")
            ModuleHelper.getNetwork(self)
            self.setNetworkDetails()
            return False
        self.parent.footer.set_text("Changes successfully applied.")
        ModuleHelper.getNetwork(self)
        self.setNetworkDetails()

        return True
Beispiel #5
0
    def apply(self, args):
        responses = self.check(args)
        if responses is False:
            self.log.error("Check failed. Not applying")
            self.parent.footer.set_text("Check failed. Not applying.")
            self.log.error("%s" % (responses))
            return False

        self.parent.footer.set_text("Applying changes... (May take up to 20s)")
        puppetclasses = []

        #If there is a gateway configured in /etc/sysconfig/network, unset it
        expr = '^GATEWAY=.*'
        replace.replaceInFile("/etc/sysconfig/network", expr, "")

        l3ifconfig = {
            'type': "resource",
            'class': "l23network::l3::ifconfig",
            'name': self.activeiface
        }
        if responses["onboot"].lower() == "no":
            params = {"ipaddr": "none"}
        elif responses["bootproto"] == "dhcp":
            self.unset_gateway()
            if "dhcp_nowait" in responses.keys():
                params = {
                    "ipaddr": "dhcp",
                    "dhcp_nowait": responses["dhcp_nowait"]
                }
            else:
                params = {"ipaddr": "dhcp"}
        else:
            cidr = network.netmaskToCidr(responses["netmask"])
            params = {
                "ipaddr": "{0}/{1}".format(responses["ipaddr"], cidr),
                "check_by_ping": "none"
            }
        if len(responses["gateway"]) > 1:
            params["gateway"] = responses["gateway"]
            self.unset_gateway()
        l3ifconfig['params'] = params
        puppetclasses.append(l3ifconfig)
        self.log.info("Puppet data: %s" % (puppetclasses))
        try:
            self.parent.refreshScreen()
            puppet.puppetApply(puppetclasses)
            ModuleHelper.getNetwork(self)
            gateway = self.get_default_gateway_linux()
            if gateway is None:
                gateway = ""
            self.fixEtcHosts()

        except Exception as e:
            self.log.error(e)
            self.parent.footer.set_text("Error applying changes. Check logs "
                                        "for details.")
            ModuleHelper.getNetwork(self)
            self.setNetworkDetails()
            return False
        self.parent.footer.set_text("Changes successfully applied.")
        ModuleHelper.getNetwork(self)
        self.setNetworkDetails()

        return True
Beispiel #6
0
    def apply(self, args):
        responses = self.check(args)
        if responses is False:
            self.log.error("Check failed. Not applying")
            self.parent.footer.set_text("Check failed. Not applying.")
            self.log.error("%s" % (responses))
            return False

        self.parent.footer.set_text("Applying changes... (May take up to 20s)")
        puppetclasses = []
        l3ifconfig = {'type': "resource",
                      'class': "l23network::l3::ifconfig",
                      'name': self.activeiface}
        if responses["onboot"].lower() == "no":
            params = {"ipaddr": "none"}
        elif responses["bootproto"] == "dhcp":
            if "dhcp_nowait" in responses.keys():
                params = {"ipaddr": "dhcp",
                          "dhcp_nowait": responses["dhcp_nowait"]}
            else:
                params = {"ipaddr": "dhcp"}
        else:
            params = {"ipaddr": responses["ipaddr"],
                      "netmask": responses["netmask"],
                      "check_by_ping": "none"}
        if len(responses["gateway"]) > 1:
            params["gateway"] = responses["gateway"]
        elif network.inSameSubnet(self.get_default_gateway_linux(),
                                  responses["ipaddr"], responses["netmask"]):
            #If the current gateway is in the same subnet AND the user
            #sets the gateway to empty, unset gateway
            expr = '^GATEWAY=.*'
            replace.replaceInFile("/etc/sysconfig/network", expr,
                                  "GATEWAY=")
        l3ifconfig['params'] = params
        puppetclasses.append(l3ifconfig)
        self.log.info("Puppet data: %s" % (puppetclasses))
        try:
            #Gateway handling so DHCP will set gateway
            if responses["bootproto"] == "dhcp":
                expr = '^GATEWAY=.*'
                replace.replaceInFile("/etc/sysconfig/network", expr,
                                      "GATEWAY=")
            self.parent.refreshScreen()
            puppet.puppetApply(puppetclasses)
            self.getNetwork()
            expr = '^GATEWAY=.*'
            gateway = self.get_default_gateway_linux()
            if gateway is None:
                gateway = ""
            replace.replaceInFile("/etc/sysconfig/network", expr, "GATEWAY=%s"
                                  % gateway)
            self.fixEtcHosts()

        except Exception as e:
            self.log.error(e)
            self.parent.footer.set_text("Error applying changes. Check logs "
                                        "for details.")
            self.getNetwork()
            self.setNetworkDetails()
            return False
        self.parent.footer.set_text("Changes successfully applied.")
        self.getNetwork()
        self.setNetworkDetails()

        return True
 def test_execute_failure(self, m_execute, m_log):
     res = (1, 'Fail', 5)
     m_execute.return_value = res
     self.assertEqual(puppet.puppetApply(self.classes), False)
     m_log.error.assert_called_once_with(
         'Exit code: %d. Error: %s Stdout: %s', res[0], res[2], res[1])
 def test_puppet_apply(self, m_execute, m_log):
     self.assertEqual(puppet.puppetApply(self.classes), True)
     m_execute.assert_called_once_with(self.command, stdin=self.input)
     m_log.info.assert_called_once_with('Puppet start')
     self.assertFalse(m_log.error.called)
Beispiel #9
0
    def apply(self, args):
        responses = self.check(args)
        if responses is False:
            self.log.error("Check failed. Not applying")
            self.parent.footer.set_text("Check failed. Not applying.")
            self.log.error("%s" % (responses))
            return False

        self.parent.footer.set_text("Applying changes... (May take up to 20s)")
        puppetclasses = []
        l3ifconfig = {
            'type': "resource",
            'class': "l23network::l3::ifconfig",
            'name': self.activeiface
        }
        if responses["onboot"].lower() == "no":
            params = {"ipaddr": "none"}
        elif responses["bootproto"] == "dhcp":
            if "dhcp_nowait" in responses.keys():
                params = {
                    "ipaddr": "dhcp",
                    "dhcp_nowait": responses["dhcp_nowait"]
                }
            else:
                params = {"ipaddr": "dhcp"}
        else:
            params = {
                "ipaddr": responses["ipaddr"],
                "netmask": responses["netmask"],
                "check_by_ping": "none"
            }
        if len(responses["gateway"]) > 1:
            params["gateway"] = responses["gateway"]
            params["default_gateway"] = True
        elif network.inSameSubnet(self.get_default_gateway_linux(),
                                  responses["ipaddr"], responses["netmask"]):
            #If the current gateway is in the same subnet AND the user
            #sets the gateway to empty, unset gateway
            expr = '^GATEWAY=.*'
            replace.replaceInFile("/etc/sysconfig/network", expr, "GATEWAY=")
        l3ifconfig['params'] = params
        puppetclasses.append(l3ifconfig)
        self.log.info("Puppet data: %s" % (puppetclasses))
        try:
            #Gateway handling so DHCP will set gateway
            if responses["bootproto"] == "dhcp":
                expr = '^GATEWAY=.*'
                replace.replaceInFile("/etc/sysconfig/network", expr,
                                      "GATEWAY=")
            self.parent.refreshScreen()
            puppet.puppetApply(puppetclasses)
            ModuleHelper.getNetwork(self)
            expr = '^GATEWAY=.*'
            gateway = self.get_default_gateway_linux()
            if gateway is None:
                gateway = ""
            replace.replaceInFile("/etc/sysconfig/network", expr,
                                  "GATEWAY=%s" % gateway)
            self.fixEtcHosts()

        except Exception as e:
            self.log.error(e)
            self.parent.footer.set_text("Error applying changes. Check logs "
                                        "for details.")
            ModuleHelper.getNetwork(self)
            self.setNetworkDetails()
            return False
        self.parent.footer.set_text("Changes successfully applied.")
        ModuleHelper.getNetwork(self)
        self.setNetworkDetails()

        return True
Beispiel #10
0
    def apply(self, args):
        responses = self.check(args)
        if responses is False:
            self.log.error("Check failed. Not applying")
            self.parent.footer.set_text("Check failed. Not applying.")
            self.log.error("%s" % (responses))
            return False

        self.parent.footer.set_text("Applying changes... (May take up to 20s)")

        # Build puppet resources to apply l23network puppet module to enable
        # network changes
        puppetclasses = []

        # FIXME(mattymo): install_bondtool param does not work (LP#1541028)
        # The following 4 lines should be removed when fixed.
        disable_bond = {
            'type': "literal",
            'name': 'K_mod <| title == "bonding" |> {ensure => absent} '
        }
        puppetclasses.append(disable_bond)

        # If there is a gateway configured in /etc/sysconfig/network, unset it
        expr = '^GATEWAY=.*'
        replace.replaceInFile("/etc/sysconfig/network", expr, "")

        # Initialize l23network class for NetworkManager fixes
        l23network = {
            'type': "resource",
            'class': "class",
            'name': "l23network",
            'params': {
                'install_bondtool': False
            }
        }
        puppetclasses.append(l23network)

        # Prepare l23network interface configuration
        l3ifconfig = {
            'type': "resource",
            'class': "l23network::l3::ifconfig",
            'name': self.activeiface
        }

        additionalclasses = []
        if responses["onboot"].lower() == "no":
            params = {"ipaddr": "none", "gateway": ""}
        elif responses["bootproto"] == "dhcp":
            additionalclasses = self.clear_gateways_except(self.activeiface)
            params = {"ipaddr": "dhcp"}
        else:
            cidr = network.addr_in_cidr_notation(responses["ipaddr"],
                                                 responses["netmask"])
            params = {"ipaddr": cidr, "check_by_ping": "none"}
            if len(responses["gateway"]) > 1:
                params["gateway"] = responses["gateway"]
                additionalclasses = self.clear_gateways_except(
                    self.activeiface)

        puppetclasses.extend(additionalclasses)
        l3ifconfig['params'] = params
        puppetclasses.append(l3ifconfig)
        self.log.info("Puppet data: %s" % (puppetclasses))

        try:
            self.parent.refreshScreen()
            result = puppet.puppetApply(puppetclasses)
            if not result:
                raise Exception("Puppet apply failed")
            modulehelper.ModuleHelper.getNetwork(self)
            gateway = self.get_default_gateway_linux()
            if gateway is None:
                gateway = ""
            self.fixEtcHosts()
            if responses['bootproto'] == 'dhcp':
                self.parent.dns_might_have_changed = True

        except Exception as e:
            self.log.error(e)
            self.parent.footer.set_text("Error applying changes. Check logs "
                                        "for details.")
            modulehelper.ModuleHelper.getNetwork(self)
            self.setNetworkDetails()
            return False
        self.parent.footer.set_text("Changes successfully applied.")
        modulehelper.ModuleHelper.getNetwork(self)
        self.setNetworkDetails()

        return True