Skip to content

Instantly share code, notes, and snippets.

@noelbk
Created August 9, 2014 00:20
Show Gist options
  • Save noelbk/fea1f9a6febb5edf7e4b to your computer and use it in GitHub Desktop.
Save noelbk/fea1f9a6febb5edf7e4b to your computer and use it in GitHub Desktop.
def _migrate_helper(self, vm, key, with_dest):
try:
vm.poll_for_status('ACTIVE')
_ip = vm.ensure_floating_ip()
host_before_migrate = vm.current_host
marker = None
with vm.ssh(pkey=key.private_key) as ssh:
marker = self.create_marker(ssh.execute)
dest = None
if with_dest:
hosts = [host['host_ip'] for host in self.find_hosts(status='ready')]
hosts.remove(vm.current_host)
dest = random.choice(list(hosts))
LOG.info('Migrating %s%s', vm, (' to %s' % dest) if dest else '')
self.cobalt.migrate(vm, dest=dest)
vm.poll_for_status('ACTIVE')
if with_dest:
self.assertEqual(vm.current_host, dest)
self.assertNotEqual(host_before_migrate, vm.current_host, 'After migration, current_host is still %s ' % host_before_migrate)
with vm.ssh(pkey=key.private_key) as ssh:
self.check_marker(ssh.execute, marker)
except Exception as e:
try:
import traceback
import subprocess
import socket
from savage import exc
traceback.print_exc()
print("Caught Exception vm ip=%s current_host=%s" % (_ip, vm.current_host,))
print("arp on localhost:\n%s" % (subprocess.check_output(('arp', '-na')),))
with self.ssh_control() as _ssh_control:
try:
for cmd in (
"arp -nv %(ip)s",
"ssh %(host)s ip addr list dev public",
"screen -d -m -S tcpdump tcpdump -l -w /tmp/tcpdump -i host",
"sleep 1",
"ping -c 3 %(host)s",
"ping -c 3 %(ip)s",
"sleep 1",
"screen -X -S tcpdump quit",
"tcpdump -r /tmp/tcpdump -vepln host %(ip)s",
):
out = err = ''
try:
cmd = cmd % dict(host=vm.current_host, ip=_ip)
out = _ssh_control.execute('bash', '-c', cmd)
err = ''
except exc.ExecutionError as e:
out = e.stdout
err = e.stderr
except socket.timeout as e:
err = traceback.format_exc()
print("control: %s\n%s" % (cmd, out.rstrip()))
err = err.rstrip()
if err:
print("stderr:\n%s" % (err,))
except Exception as e2:
import pdb; pdb.set_trace()
with self.ssh_host_execute(vm.current_host) as _ssh:
import pdb; pdb.set_trace()
except Exception as e2:
import pdb; pdb.set_trace()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment