From 1aef4b43c38e6e36495ed85915a687651070ec49 Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Fri, 17 May 2013 13:12:55 +0100 Subject: [PATCH] Add new patches for fedora. Patches are needed to improve fedora build host support. --- ...ibvirt-to-create-and-destroy-bridges.patch | 171 ++++++++++++++++++ ...r-0002-Abstract-kvm-executable-names.patch | 70 +++++++ ...0001-Dont-hard-code-libvirt-emulator.patch | 45 +++++ ...002-Update-the-libvirt-configuration.patch | 61 +++++++ .../incubator-0003-Remove-yum-update.patch | 31 ++++ 5 files changed, 378 insertions(+) create mode 100644 patches/bm_poseur-0001-use-Libvirt-to-create-and-destroy-bridges.patch create mode 100644 patches/bm_poseur-0002-Abstract-kvm-executable-names.patch create mode 100644 patches/incubator-0001-Dont-hard-code-libvirt-emulator.patch create mode 100644 patches/incubator-0002-Update-the-libvirt-configuration.patch create mode 100644 patches/incubator-0003-Remove-yum-update.patch diff --git a/patches/bm_poseur-0001-use-Libvirt-to-create-and-destroy-bridges.patch b/patches/bm_poseur-0001-use-Libvirt-to-create-and-destroy-bridges.patch new file mode 100644 index 000000000..dae869415 --- /dev/null +++ b/patches/bm_poseur-0001-use-Libvirt-to-create-and-destroy-bridges.patch @@ -0,0 +1,171 @@ +From e3fec050e24a30b93dac3afe3b6615aafc049cf1 Mon Sep 17 00:00:00 2001 +From: Lucas Alvares Gomes +Date: Thu, 16 May 2013 16:45:36 +0100 +Subject: [PATCH] Libvirt to create and destroy bridges. + +Modifying networking information directly via /etc/network/interfaces +is not cross-distro compatible. +--- + lib/actions.py | 96 ++++++++++++++++++++++++---------------------------------- + 1 file changed, 39 insertions(+), 57 deletions(-) + +diff --git a/lib/actions.py b/lib/actions.py +index f0a3e95..0ed5f44 100755 +--- a/lib/actions.py ++++ b/lib/actions.py +@@ -24,6 +24,7 @@ + from textwrap import dedent + import re + from lxml import objectify ++from lxml import etree + from collections import defaultdict + + def call(*args, **kwargs): +@@ -47,14 +48,6 @@ def __call__(self, parser, params, values, option_string=None, **kwargs): + self._print(self.params, verbose=True) + + self.conn=libvirt.open(self.params.qemu) +- self.bridge_template = dedent( """\ +- +- # bm_poseur bridge +- auto %(bridge)s +- iface %(bridge)s inet manual +- bridge_ports %(ports)s #bmposeur +- +- """) + + # action function mapping + actions = { 'create-vm' : self.create_vms, +@@ -91,42 +84,27 @@ def get_macs(self): + for domain in domains: + if not domain.find(self.params.prefix) == -1: + _xml = objectify.fromstring(self.conn.lookupByName(domain).XMLDesc(0)) +- ++ + output += "%s" % _xml.devices.interface[0].mac.attrib.get("address") + try: + output += ",%s " % _xml.devices.interface[1].mac.attrib.get("address") + except IndexError: + output += " " + +- ++ + print '%s' % output.strip(' ') + + + def destroy_bridge(self): + """ This destroys the bridge """ +- self._print("reading network config file", True) +- +- # remove the route first +- idx=self.params.bridge_ip.rindex('.') +- net=self.params.bridge_ip[0:idx] + ".0" +- call('route del -net %s netmask 255.255.255.0' % net, shell=True) +- +- # take the bridge down +- call('ifdown %s' % self.params.bridge, shell=True) +- +- network_file = open(self.params.network_config, 'r').read() +- ports = " ".join(self.params.bridge_port) or "none" +- to_remove = self.bridge_template % dict(bridge=self.params.bridge, ports=ports) +- to_remove = to_remove.strip().splitlines() +- +- self._print("clearing bridge", True) +- for line in to_remove: +- network_file = network_file.replace(line,'') ++ if not self.is_already_bridge(): ++ self._print('%s network not found' % self.params.bridge) ++ return + +- self._print("writing changed network config file", True) +- outf = open( self.params.network_config , "w") +- outf.write(network_file.strip()) +- outf.close() ++ network = self.conn.networkLookupByName(self.params.bridge) ++ if network.isActive(): ++ network.destroy() ++ network.undefine() + + self._print("removing dnsmasq exclusion file", True) + try: +@@ -138,12 +116,30 @@ def destroy_bridge(self): + + def is_already_bridge(self): + """ returns t/f if a bridge exists or not """ +- network_file = open(self.params.network_config, 'r').read() +- if network_file.find(self.params.bridge) == -1: +- return False +- else: +- return True ++ #listNetworks = list the active networks ++ #listDefinedNetworks = list the inactive networks ++ all_networks = self.conn.listNetworks() + \ ++ self.conn.listDefinedNetworks() ++ return self.params.bridge in all_networks ++ ++ def build_bridge_xml(self): ++ """ """ ++ root = etree.Element('network') ++ name_el = etree.SubElement(root, 'name') ++ name_el.text = self.params.bridge ++ ++ stp = "on" if len(self.params.bridge_port) > 1 else "off" ++ bridge_el = etree.SubElement(root, 'bridge', ++ name=self.params.bridge, ++ stp=stp) + ++ if self.params.bridge_ip and self.params.bridge_ip.lower() != 'none': ++ etree.SubElement(root, 'ip', address=self.params.bridge_ip) ++ ++ for p in self.params.bridge_port: ++ etree.SubElement(root, 'forward', mode='route', dev=p) ++ ++ return etree.tostring(root) + + def create_bridge(self): + """ this creates a bridge """ +@@ -152,21 +148,11 @@ def create_bridge(self): + print('bridge already exists') + return + +- self._print("Creating bridge interface %(bridge)s." % +- dict(bridge=self.params.bridge), verbose=True) +- +- ports = " ".join(self.params.bridge_port) or "none" +- +- self._print(" Writing new stanza for bridge interface %(bridge)s." % +- dict(bridge=self.params.bridge), verbose=True) +- +- with file(self.params.network_config, 'ab') as outf: +- outf.seek(0, 2) +- outf.write(self.bridge_template % dict(bridge=self.params.bridge, ports=ports)) +- +- self._print(" Wrote new stanza for bridge interface %s." % ++ self._print(" Creating a new bridge interface %s." % + self.params.bridge, verbose=True) + ++ self.conn.networkDefineXML(self.build_bridge_xml()) ++ + self._print(" Writing dnsmasq.d exclusion file.", verbose=True) + + with file('/etc/dnsmasq.d/%(bridge)s' % dict(bridge=self.params.bridge), 'wb') as outf: +@@ -177,13 +163,9 @@ def create_bridge(self): + self.params.bridge, verbose=True) + + self._print('bring bridge online') +- call('ifup %s ' % self.params.bridge , shell=True) +- if self.params.bridge_ip and self.params.bridge_ip.lower() != 'none': +- # XXX: This should change the stanza rather than calling ip +- self._print('Assigning IP %s to bridge' % self.params.bridge_ip) +- call('ip addr add dev %s local %s/24 scope global' % +- (self.params.bridge, self.params.bridge_ip), +- shell=True) ++ network = self.conn.networkLookupByName(self.params.bridge) ++ network.setAutostart(True) ++ network.create() + + #idx=self.params.bridge_ip.rindex('.') + #net=self.params.bridge_ip[0:idx] + ".0" +-- +1.8.1.6 + diff --git a/patches/bm_poseur-0002-Abstract-kvm-executable-names.patch b/patches/bm_poseur-0002-Abstract-kvm-executable-names.patch new file mode 100644 index 000000000..0210ae411 --- /dev/null +++ b/patches/bm_poseur-0002-Abstract-kvm-executable-names.patch @@ -0,0 +1,70 @@ +From c2edd258fcdd76f6a4f4fa31bbc989268833d803 Mon Sep 17 00:00:00 2001 +From: Lucas Alvares Gomes +Date: Fri, 17 May 2013 11:14:25 +0100 +Subject: [PATCH 1/1] Abstract KVM executable name. + +RedHat and Debian based systems have different executable names. +--- + lib/actions.py | 18 +++++++++++++++++- + lib/template.xml | 2 +- + 2 files changed, 18 insertions(+), 2 deletions(-) + +diff --git a/lib/actions.py b/lib/actions.py +index 0ed5f44..a9c68d9 100755 +--- a/lib/actions.py ++++ b/lib/actions.py +@@ -174,6 +174,20 @@ class actions(argparse.Action): + # (net, self.params.bridge), + # shell=True) + ++ def get_emulator(self): ++ """ ++ Return the right emulator. RedHat and Debian based systems have ++ different executable names. ++ """ ++ if os.path.exists("/usr/bin/kvm"): # Debian ++ return "/usr/bin/kvm" ++ elif os.path.exists("/usr/bin/qemu-kvm"): # Redhat ++ return "/usr/bin/qemu-kvm" ++ else: ++ self._print("ERROR: Emulator not found. You need to have either " ++ "kvm or qemu-kvm installed before continue.") ++ sys.exit(1) ++ + def load_xml(self, name, image): + """Loads the xml file and evals it with the right settings""" + self._print('load_xml called') +@@ -187,6 +201,7 @@ class actions(argparse.Action): + name=name, + max_mem=self.params.max_mem, + cpus=self.params.cpus, ++ emulator=self.get_emulator(), + image=image ) + + +@@ -218,7 +233,8 @@ class actions(argparse.Action): + name = "%s%s" % (self.params.prefix , str(i)) + image = "%s%s.img" % (self.params.image_path, name) + call("sudo rm -f %s" % image, shell=True) +- cmd = "kvm-img create -f raw %s %s" % (image, self.params.disk_size) ++ cmd = "qemu-img create -f raw %s %s" % (image, ++ self.params.disk_size) + call(cmd, shell=True) + + self.conn.defineXML(self.load_xml(name,image)) +diff --git a/lib/template.xml b/lib/template.xml +index 59f5391..388e16e 100644 +--- a/lib/template.xml ++++ b/lib/template.xml +@@ -18,7 +18,7 @@ + restart + restart + +- /usr/bin/kvm ++ %(emulator)s + + + +-- +1.8.1.4 + diff --git a/patches/incubator-0001-Dont-hard-code-libvirt-emulator.patch b/patches/incubator-0001-Dont-hard-code-libvirt-emulator.patch new file mode 100644 index 000000000..e2df0628d --- /dev/null +++ b/patches/incubator-0001-Dont-hard-code-libvirt-emulator.patch @@ -0,0 +1,45 @@ +From 941862202864ed2f65018b5af3f8b5d340ba5116 Mon Sep 17 00:00:00 2001 +From: Dan Prince +Date: Thu, 16 May 2013 13:54:56 -0400 +Subject: [PATCH] Don't hard code libvirt emulator. + +Updates configure-bootstrap-vm so that it determines the correct +location of the emulator binary and injects it as a parameter +into the libvirt template. +--- + bootstrap/bootstrap.xml | 2 +- + bootstrap/configure-bootstrap-vm | 5 +++++ + 2 files changed, 6 insertions(+), 1 deletion(-) + +diff --git a/bootstrap/bootstrap.xml b/bootstrap/bootstrap.xml +index 726022e..1425e7e 100644 +--- a/bootstrap/bootstrap.xml ++++ b/bootstrap/bootstrap.xml +@@ -16,7 +16,7 @@ + restart + restart + +- /usr/bin/kvm ++ %(emulator)s + + + +diff --git a/bootstrap/configure-bootstrap-vm b/bootstrap/configure-bootstrap-vm +index 665fbf2..97d6187 100755 +--- a/bootstrap/configure-bootstrap-vm ++++ b/bootstrap/configure-bootstrap-vm +@@ -34,6 +34,11 @@ def main(): + if args.image is not None: + params['imagefile'] = args.image + ++ if os.path.exists("/usr/bin/kvm"): # Debian ++ params['emulator'] = "/usr/bin/kvm" ++ elif os.path.exists("/usr/bin/qemu-kvm"): # Redhat ++ params['emulator'] = "/usr/bin/qemu-kvm" ++ + libvirt_template = source_template % params + conn=libvirt.open("qemu:///system") + a = conn.defineXML(libvirt_template) +-- +1.8.1.6 + diff --git a/patches/incubator-0002-Update-the-libvirt-configuration.patch b/patches/incubator-0002-Update-the-libvirt-configuration.patch new file mode 100644 index 000000000..2d139a3eb --- /dev/null +++ b/patches/incubator-0002-Update-the-libvirt-configuration.patch @@ -0,0 +1,61 @@ +From 3e3cbfc54eeea3a63f0629036a8c56db6dc6fc7b Mon Sep 17 00:00:00 2001 +From: Lucas Alvares Gomes +Date: Fri, 17 May 2013 10:22:02 +0100 +Subject: [PATCH] Update the libvirt configuration. + +Management access to libvirt is controlled through membership to a unix +group, on fedora/rhel we need to updated the libvirt configuration to +give management access to the libvirtd group. +--- + scripts/install-dependencies | 28 +++++++++++++++++++--------- + 1 file changed, 19 insertions(+), 9 deletions(-) + +diff --git a/scripts/install-dependencies b/scripts/install-dependencies +index d976c98..7f8b1d2 100755 +--- a/scripts/install-dependencies ++++ b/scripts/install-dependencies +@@ -6,15 +6,6 @@ if ! grep "$(cat ~/.ssh/id_rsa.pub)" ~/.ssh/authorized_keys >/dev/null; then + cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys + fi + +-# libvirtd group +-grep libvirtd /etc/group || sudo groupadd libvirtd +-if ! id | grep libvirtd; then +- echo "adding $USER to group libvirtd" +- sudo usermod -a -G libvirtd $USER +- exec sudo su -l $USER $PWD/$0 +- PRINT_RESTART=1 +-fi +- + # packages + os=unsupported + if [ -f /etc/redhat-release ]; then +@@ -56,6 +47,25 @@ if [ "$os" = "redhat" ]; then + sudo service libvirtd restart + fi + ++# libvirtd group ++grep libvirtd /etc/group || sudo groupadd libvirtd ++if ! id | grep libvirtd; then ++ echo "adding $USER to group libvirtd" ++ sudo usermod -a -G libvirtd $USER ++ ++ if [ "$os" = "redhat" ]; then ++ libvirtd_file=/etc/libvirt/libvirtd.conf ++ if ! sudo grep "^unix_sock_group" $libvirtd_file > /dev/null; then ++ sudo sed -i 's/^#unix_sock_group.*/unix_sock_group = "libvirtd"/g' $libvirtd_file ++ sudo sed -i 's/^#auth_unix_rw.*/auth_unix_rw = "none"/g' $libvirtd_file ++ sudo sed -i 's/^#unix_sock_rw_perms.*/unix_sock_rw_perms = "0770"/g' $libvirtd_file ++ sudo service libvirtd restart ++ fi ++ fi ++ ++ exec sudo su -l $USER $PWD/$0 ++fi ++ + echo "Check to see that you are in the libvirtd group in your current shell before going on. You can check by running:" + echo + echo "id | grep libvirtd" +-- +1.8.1.6 + diff --git a/patches/incubator-0003-Remove-yum-update.patch b/patches/incubator-0003-Remove-yum-update.patch new file mode 100644 index 000000000..504720156 --- /dev/null +++ b/patches/incubator-0003-Remove-yum-update.patch @@ -0,0 +1,31 @@ +From 805222d71ba8d4f3d80a6ddb14ae82dc9fac01e9 Mon Sep 17 00:00:00 2001 +From: Lucas Alvares Gomes +Date: Fri, 17 May 2013 12:03:04 +0100 +Subject: [PATCH 1/1] Remove yum update. + +Remove the yum update because we want to install some dependencies +and not update the whole system. Audit was added to the list +of dependencies to avoid conflict with the glibc package: +https://bugzilla.redhat.com/show_bug.cgi?id=949745 +--- + scripts/install-dependencies | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +diff --git a/scripts/install-dependencies b/scripts/install-dependencies +index d976c98..d4abf8b 100755 +--- a/scripts/install-dependencies ++++ b/scripts/install-dependencies +@@ -47,9 +47,8 @@ if [ "$os" = "debian" ]; then + fi + + if [ "$os" = "redhat" ]; then +- sudo yum update -y + # For RHEL/CentOS, python-pip is in EPEL +- sudo yum install -y python-lxml libvirt-python libvirt qemu-kvm git python-pip openssl-devel python-devel gcc ++ sudo yum install -y python-lxml libvirt-python libvirt qemu-kvm git python-pip openssl-devel python-devel gcc audit + + sudo pip-python install -U python-novaclient python-glanceclient python-heatclient python-keystoneclient + +-- +1.8.1.4 +