From 9e44cabff98ea61df66d49e47f5ca9812de30c9d Mon Sep 17 00:00:00 2001 From: ZhuoX Li Date: Fri, 17 Oct 2014 09:49:31 +0800 Subject: [PATCH] Add MAC addrees into mic-appliance. When create imager, Mic-appliance is started without specified MAC address. As the result, all mic-appliance instances that run in same network, get also same default MAC address. This potentially leads to collisions and conflicts in addressing mic-appliance VM sessions. So need to add unique MAC addresses, when run mic-appliance. Fixes: #2132 Change-Id: I870798cabb8f6043a4a0182619b8e49c04fdba59 --- job_imager.py | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/job_imager.py b/job_imager.py index 65265d0..738f89d 100755 --- a/job_imager.py +++ b/job_imager.py @@ -36,17 +36,40 @@ def convert_image_dir(image_dir, repo_name, image_name): return shutil.move(image_name, repo_name) +def octet_type(num): + """ + change int data to the same otctet type + """ + return '%02x' % int(num) + +def create_mac(): + """ + create unique MAC address from static part=52, + node IP, slot number, process number + """ + ssh_connection = os.getenv('SSH_CONNECTION') + exe_number = os.getenv('EXECUTOR_NUMBER', '1') + pid = os.getpid() + nodenum = octet_type(ssh_connection.split(' ')[2].split('.')[3]) + slotnum = octet_type(int(exe_number)%256) + p_1 = pid/65536 + p_2 = pid/256 + p_3 = pid - p_2*256 + return '52:%s:%s:%s:%s:%s' % \ + (nodenum, slotnum, octet_type(p_1), octet_type(p_2), octet_type(p_3)) + def run_inside_vm(vm_image, vm_memory, vm_cpus, basedir): """ Run mic inside VM basedir(usually $WORKSPACE/mic) is shared by VM as Plan9 mount for cache and results """ - cmd = 'qemu-system-x86_64 -machine accel=kvm:xen:tcg -name opensuse '\ - '-M pc -m %d -smp %d -vga none -drive file=%s,snapshot=on '\ - '-nographic -virtfs local,id=test_dev,path=%s, '\ - 'security_model=mapped,mount_tag=share' % \ - (vm_memory, vm_cpus, vm_image, basedir) + cmd = 'qemu-system-x86_64 -machine accel=kvm:xen:tcg -name '\ + 'opensuse -M pc -m %d -smp %d -vga none -drive file=%s,'\ + 'snapshot=on -nographic -virtfs local,id=test_dev,'\ + 'path=%s,security_model=mapped,mount_tag=share '\ + '-net nic,macaddr=%s -net user' % \ + (vm_memory, vm_cpus, vm_image, basedir, create_mac()) subprocess.call(cmd, stdout=sys.stdout, stderr=sys.stderr, shell=True) -- 2.7.4