Skip to content

Instantly share code, notes, and snippets.

@salv-orlando
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salv-orlando/8715991 to your computer and use it in GitHub Desktop.
Save salv-orlando/8715991 to your computer and use it in GitHub Desktop.
stress processes in metadata
while :
do
echo "BOOTING VMs"
nova boot --flavor 84 --image $1 --nic net-id=$2 --key-name test-key test1
nova boot --flavor 84 --image $1 --nic net-id=$2 --key-name test-key test2
nova boot --flavor 84 --image $1 --nic net-id=$2 --key-name test-key test3
nova boot --flavor 84 --image $1 --nic net-id=$2 --key-name test-key test4
nova boot --flavor 84 --image $1 --nic net-id=$2 --key-name test-key test5
nova boot --flavor 84 --image $1 --nic net-id=$2 --key-name test-key test6
nova boot --flavor 84 --image $1 --nic net-id=$2 --key-name test-key test7
nova boot --flavor 84 --image $1 --nic net-id=$2 --key-name test-key test8
nova boot --flavor 84 --image $1 --nic net-id=$2 --key-name test-key test9
sleep 5
num_active=$(nova list | grep ACTIVE | wc -l)
while [ $num_active -ne 9 ]; do
num_active=$(nova list | grep ACTIVE | wc -l)
echo "WAITING FOR VMs to become active. Currently:"$num_active
done
nova delete test1
nova delete test2
nova delete test3
nova delete test4
nova delete test5
nova delete test6
nova delete test7
nova delete test8
nova delete test9
sleep 3
while [ $num_active -ne 0 ]; do
num_active=$(nova list | grep ACTIVE | wc -l)
echo "WAITING FOR VMs to DIE. Currently:"$num_active
done
done
import time
import uuid
import eventlet
from neutron.agent.linux import external_process
from neutron.agent.linux import ip_lib
eventlet.monkey_patch()
state_path = '/opt/stack/data/neutron'
metadata_proxy_socket = '%s/metadata_proxy' % state_path
metadata_port = 9697
class Conf(object):
external_pids = "%s/external/pids" % state_path
conf = Conf()
def create_router_namespace(ns_name):
ip_wrapper_root = ip_lib.IPWrapper('sudo')
ip_wrapper = ip_wrapper_root.ensure_namespace(ns_name)
ip_wrapper.netns.execute(['sysctl', '-w', 'net.ipv4.ip_forward=1'])
def spawn_metadata_proxy(router_id, ns_name):
def callback(pid_file):
proxy_cmd = ['neutron-ns-metadata-proxy',
'--pid_file=%s' % pid_file,
'--metadata_proxy_socket=%s' % metadata_proxy_socket,
'--router_id=%s' % router_id,
'--state_path=%s' % state_path,
'--metadata_port=%s' % metadata_port]
return proxy_cmd
pm = external_process.ProcessManager(
conf,
router_id,
'sudo',
ns_name)
pm.enable(callback)
return pm
def destroy_router_namespace(namespace):
ns_ip = ip_lib.IPWrapper('sudo', namespace=namespace)
try:
ns_ip.netns.delete(namespace)
except RuntimeError:
msg = _('Failed trying to delete namespace: %s')
print(msg % namespace)
while True:
def process_stuff():
fake_rtr_id = str(uuid.uuid4())
ns_name = "test-%s" % fake_rtr_id
print "create namespace %s..." % ns_name
create_router_namespace(ns_name)
print "spawn metadata process in namespace %s..." % ns_name
pm = spawn_metadata_proxy(fake_rtr_id, ns_name)
print "wait 240 seconds..."
time.sleep(240)
print "kill metadata processi in namespace %s..." % ns_name
pm.disable()
print "wait 120 seconds..."
print "delete namespacei %s..." % ns_name
destroy_router_namespace(ns_name)
print "starting a new thing..."
eventlet.spawn_n(process_stuff)
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment