def test(self): entry_point = self.mox.CreateMock(pkg_resources.EntryPoint) self.mox.StubOutWithMock(pkg_resources, 'iter_entry_points') pkg_resources.iter_entry_points( 'debmarshal.distributions', name='base').AndReturn( (x for x in [entry_point])) entry_point.load().AndReturn(object) self.mox.ReplayAll() self.assertEqual(base.findDistribution('base'), object)
def test(self): entry_point = self.mox.CreateMock(pkg_resources.EntryPoint) self.mox.StubOutWithMock(pkg_resources, 'iter_entry_points') pkg_resources.iter_entry_points( 'debmarshal.distributions', name='base').AndReturn( (x for x in [entry_point])) entry_point.load().AndReturn(object) self.mox.ReplayAll() self.assertEqual(base.findDistribution('base'), object)
def runTest(test): """Actually run a debmarshal test. Args: Path to the test to run. """ start = time.time() # First, load the configuration config = yaml.safe_load(open(os.path.join(test, 'config.yml'))) # Next, network configuration. Configure the network as it will be # for the test run. vms = config['vms'].keys() net_name, net_gate, net_mask, net_vms = privops.call('createNetwork', vms) try: # Then, spawn the web server for serving the test configuration. httpd = subprocess.Popen(['python', '-m', 'debmarshal.web', test], stdout=subprocess.PIPE) web_port = httpd.stdout.read() domain = config['domain'] try: images = {} domains = {} for vm in vms: vm_config = config['vms'][vm] dist = base.findDistribution(vm_config['distribution']) pristine_disk_path = dist.diskPath(vm, domain, test, vm_config) fd, disk_path = tempfile.mkstemp() os.close(fd) subprocess.check_call(['cp', '--sparse=always', pristine_disk_path, disk_path], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) images[vm] = disk_path for vm in vms: vm_config = config['vms'][vm] memory = vm_config.get('memory', '128M') arch = vm_config.get('arch', '') domains[vm] = privops.call('createDomain', memory, [images[vm]], net_name, net_vms[vm][1], 'qemu', arch, {}) # Wait for the master VM to boot up, then run the test key_path = os.path.join(test, 'id_rsa') master = vms[0] master_ip = net_vms[master][0] while True: if not subprocess.call(['ssh', '-i', key_path, '-o', 'ConnectTimeout=1', '-l', 'root', master_ip, 'true'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE): break else: time.sleep(5) subprocess.check_call(['ssh', '-i', key_path, '-l', 'root', master_ip, 'wget', '-N', '-O', '/root/script', 'http://%s:%s/script' % (net_gate, web_port)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) ret = subprocess.call(['ssh', '-i', key_path, '-l', 'root', master_ip, '/root/script', str(web_port)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) print ret finally: for domain in domains.values(): privops.call('destroyDomain', domain, 'qemu') for image in images.values(): os.unlink(image) os.kill(httpd.pid, signal.SIGTERM) finally: privops.call('destroyNetwork', net_name)
def prepareTest(test): """Prepare the disk image for a single test. Args: Path to a debmarshal test. """ start = time.time() # First, load the configuration config = yaml.safe_load(open(os.path.join(test, 'config.yml'))) # Next, network configuration. Configure the network as it will be # for the test run. vms = config['vms'].keys() net_name, net_gate, net_mask, net_vms = privops.call('createNetwork', vms) # If there's not already an ssh key packaged with the test to use, # generate one. key_path = os.path.join(test, 'id_rsa') if not os.path.exists(key_path): subprocess.check_call(['ssh-keygen', '-N', '', '-f', key_path], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) try: # Then, spawn the web server for serving the test configuration. httpd = subprocess.Popen(['python', '-m', 'debmarshal.web', test], stdout=subprocess.PIPE) web_port = httpd.stdout.read() try: results_queue = Queue.Queue() threads = [] # For each VM that needs to be installed, create a thread to run # the installer for vm in vms: dist = base.findDistribution(config['vms'][vm]['distribution']) threads.append(threading.Thread( target=dist.doInstall, args=(test, vm, net_name, net_gate, net_vms[vm][1], web_port, results_queue))) # Ready, set, go! for t in threads: t.start() # Wait until all of the threads have completed execution for t in threads: t.join() return prepareSummary(results_queue, start) finally: os.kill(httpd.pid, signal.SIGTERM) finally: privops.call('destroyNetwork', net_name)
def runTest(test): """Actually run a debmarshal test. Args: Path to the test to run. """ start = time.time() # First, load the configuration config = yaml.safe_load(open(os.path.join(test, "config.yml"))) # Next, network configuration. Configure the network as it will be # for the test run. vms = config["vms"].keys() net_name, net_gate, net_mask, net_vms = privops.call("createNetwork", vms) try: # Then, spawn the web server for serving the test configuration. httpd = subprocess.Popen(["python", "-m", "debmarshal.web", test], stdout=subprocess.PIPE) web_port = httpd.stdout.read() domain = config["domain"] try: images = {} domains = {} for vm in vms: vm_config = config["vms"][vm] dist = base.findDistribution(vm_config["distribution"]) pristine_disk_path = dist.diskPath(vm, domain, test, vm_config) fd, disk_path = tempfile.mkstemp() os.close(fd) subprocess.check_call( ["cp", "--sparse=always", pristine_disk_path, disk_path], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) images[vm] = disk_path for vm in vms: vm_config = config["vms"][vm] memory = vm_config.get("memory", "128M") arch = vm_config.get("arch", "") domains[vm] = privops.call( "createDomain", memory, [images[vm]], net_name, net_vms[vm][1], "qemu", arch, {} ) # Wait for the master VM to boot up, then run the test key_path = os.path.join(test, "id_rsa") master = vms[0] master_ip = net_vms[master][0] while True: if not subprocess.call( ["ssh", "-i", key_path, "-o", "ConnectTimeout=1", "-l", "root", master_ip, "true"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ): break else: time.sleep(5) subprocess.check_call( [ "ssh", "-i", key_path, "-l", "root", master_ip, "wget", "-N", "-O", "/root/script", "http://%s:%s/script" % (net_gate, web_port), ], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) ret = subprocess.call( ["ssh", "-i", key_path, "-l", "root", master_ip, "/root/script", str(web_port)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) print ret finally: for domain in domains.values(): privops.call("destroyDomain", domain, "qemu") for image in images.values(): os.unlink(image) os.kill(httpd.pid, signal.SIGTERM) finally: privops.call("destroyNetwork", net_name)
def prepareTest(test): """Prepare the disk image for a single test. Args: Path to a debmarshal test. """ start = time.time() # First, load the configuration config = yaml.safe_load(open(os.path.join(test, "config.yml"))) # Next, network configuration. Configure the network as it will be # for the test run. vms = config["vms"].keys() net_name, net_gate, net_mask, net_vms = privops.call("createNetwork", vms) # If there's not already an ssh key packaged with the test to use, # generate one. key_path = os.path.join(test, "id_rsa") if not os.path.exists(key_path): subprocess.check_call( ["ssh-keygen", "-N", "", "-f", key_path], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) try: # Then, spawn the web server for serving the test configuration. httpd = subprocess.Popen(["python", "-m", "debmarshal.web", test], stdout=subprocess.PIPE) web_port = httpd.stdout.read() try: results_queue = Queue.Queue() threads = [] # For each VM that needs to be installed, create a thread to run # the installer for vm in vms: dist = base.findDistribution(config["vms"][vm]["distribution"]) threads.append( threading.Thread( target=dist.doInstall, args=(test, vm, net_name, net_gate, net_vms[vm][1], web_port, results_queue), ) ) # Ready, set, go! for t in threads: t.start() # Wait until all of the threads have completed execution for t in threads: t.join() return prepareSummary(results_queue, start) finally: os.kill(httpd.pid, signal.SIGTERM) finally: privops.call("destroyNetwork", net_name)