本文整理汇总了Python中contrail_vrouter_api.vrouter_api.ContrailVRouterApi.periodic_connection_check方法的典型用法代码示例。如果您正苦于以下问题:Python ContrailVRouterApi.periodic_connection_check方法的具体用法?Python ContrailVRouterApi.periodic_connection_check怎么用?Python ContrailVRouterApi.periodic_connection_check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类contrail_vrouter_api.vrouter_api.ContrailVRouterApi
的用法示例。
在下文中一共展示了ContrailVRouterApi.periodic_connection_check方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NetnsMonitor
# 需要导入模块: from contrail_vrouter_api.vrouter_api import ContrailVRouterApi [as 别名]
# 或者: from contrail_vrouter_api.vrouter_api.ContrailVRouterApi import periodic_connection_check [as 别名]
class NetnsMonitor(object):
def __init__(self, project, vm_obj, vmi_obj, ifname, **kwargs):
self.project = project
self.vm = vm_obj
self.vmi = vmi_obj
self.ifname = ifname
self.vmi_out = kwargs.get('vmi_out', None)
self.ifname_out = kwargs.get('ifname_out', None)
vrouter_semaphore = gevent.lock.Semaphore()
self.vrouter_client = ContrailVRouterApi(doconnect=True,
semaphore=vrouter_semaphore)
self.vrouter_client.connect()
self.vrouter_agent_connection = self.vrouter_client._client
def keepalive(self):
self.vrouter_client.periodic_connection_check()
current_agent_connection = self.vrouter_client._client
if not current_agent_connection:
# vrouter agent is down, Try checking...
return
if self.vrouter_agent_connection != current_agent_connection:
# Initial connection object to vrouter agent is different from
# the current object, vrouter agent is restarted, plug the netns
# vif's again.
interface_register(self.vm, self.vmi, self.ifname,
project=self.project)
if self.vmi_out:
interface_register(self.vm, self.vmi_out, self.ifname_out,
project=self.project)
self.vrouter_agent_connection = current_agent_connection
def monitor(self):
while True:
gevent.sleep(INTERVAL)
self.keepalive()
示例2: VRouterVIFDriver
# 需要导入模块: from contrail_vrouter_api.vrouter_api import ContrailVRouterApi [as 别名]
# 或者: from contrail_vrouter_api.vrouter_api.ContrailVRouterApi import periodic_connection_check [as 别名]
class VRouterVIFDriver(LibvirtBaseVIFDriver):
"""VIF driver for VRouter when running Neutron."""
PORT_TYPE = 'NovaVMPort'
def __init__(self, get_connection):
super(VRouterVIFDriver, self).__init__(get_connection)
self._vrouter_client = ContrailVRouterApi()
timer = loopingcall.FixedIntervalLoopingCall(self._keep_alive)
timer.start(interval=2)
def _keep_alive(self):
self._vrouter_client.periodic_connection_check()
def get_config(self, instance, vif, image_meta, inst_type):
conf = super(VRouterVIFDriver, self).get_config(instance, vif,
image_meta, inst_type)
dev = self.get_vif_devname(vif)
designer.set_vif_host_backend_ethernet_config(conf, dev)
designer.set_vif_bandwidth_config(conf, inst_type)
return conf
def plug(self, instance, vif):
dev = self.get_vif_devname(vif)
try:
linux_net.create_tap_dev(dev)
except processutils.ProcessExecutionError:
LOG.exception(_LE("Failed while plugging vif"), instance=instance)
kwargs = {
'ip_address': vif['network']['subnets'][0]['ips'][0]['address'],
'vn_id': vif['network']['id'],
'display_name': instance['display_name'],
'hostname': instance['hostname'],
'host': instance['host'],
'vm_project_id': instance['project_id'],
'port_type': self.PORT_TYPE,
}
try:
result = self._vrouter_client.add_port(instance['uuid'],
vif['id'],
dev,
vif['address'],
**kwargs)
if not result:
LOG.exception(_LE("Failed while plugging vif"),
instance=instance)
except TApplicationException:
LOG.exception(_LE("Failed while plugging vif"), instance=instance)
def unplug(self, instance, vif):
dev = self.get_vif_devname(vif)
try:
self._vrouter_client.delete_port(vif['id'])
linux_net.delete_net_dev(dev)
except (TApplicationException, processutils.ProcessExecutionError):
LOG.exception(_LE("Failed while unplugging vif"),
instance=instance)
示例3: OpenContrailVIFDriver
# 需要导入模块: from contrail_vrouter_api.vrouter_api import ContrailVRouterApi [as 别名]
# 或者: from contrail_vrouter_api.vrouter_api.ContrailVRouterApi import periodic_connection_check [as 别名]
class OpenContrailVIFDriver(object):
def __init__(self):
self._vrouter_semaphore = eventlet.semaphore.Semaphore()
self._vrouter_client = ContrailVRouterApi(
doconnect=True, semaphore=self._vrouter_semaphore)
timer = loopingcall.FixedIntervalLoopingCall(self._keep_alive)
timer.start(interval=2)
def _keep_alive(self):
self._vrouter_client.periodic_connection_check()
def plug(self, instance, vif):
vif_type = vif['type']
LOG.debug('Plug vif_type=%(vif_type)s instance=%(instance)s '
'vif=%(vif)s',
{'vif_type': vif_type, 'instance': instance,
'vif': vif})
if_local_name = 'veth%s' % vif['id'][:8]
if_remote_name = 'ns%s' % vif['id'][:8]
# Device already exists so return.
if linux_net.device_exists(if_local_name):
return
undo_mgr = utils.UndoManager()
try:
utils.execute('ip', 'link', 'add', if_local_name, 'type', 'veth',
'peer', 'name', if_remote_name, run_as_root=True)
undo_mgr.undo_with(lambda: utils.execute(
'ip', 'link', 'delete', if_local_name, run_as_root=True))
utils.execute('ip', 'link', 'set', if_remote_name, 'address',
vif['address'], run_as_root=True)
except Exception:
LOG.exception("Failed to configure network")
msg = _('Failed to setup the network, rolling back')
undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
def attach(self, instance, vif, container_id):
vif_type = vif['type']
LOG.debug('Attach vif_type=%(vif_type)s instance=%(instance)s '
'vif=%(vif)s',
{'vif_type': vif_type, 'instance': instance,
'vif': vif})
if_local_name = 'veth%s' % vif['id'][:8]
if_remote_name = 'ns%s' % vif['id'][:8]
undo_mgr = utils.UndoManager()
undo_mgr.undo_with(lambda: utils.execute(
'ip', 'link', 'delete', if_local_name, run_as_root=True))
ipv4_address, ipv4_netmask, ipv4_gateway = self._retrieve_ip_address(
vif, 4)
ipv6_address, ipv6_netmask, ipv6_gateway = self._retrieve_ip_address(
vif, 6)
ipv4_address = ipv4_address or '0.0.0.0'
params = {
'ip_address': ipv4_address,
'vn_id': vif['network']['id'],
'display_name': instance['display_name'],
'hostname': instance['hostname'],
'host': instance['host'],
'vm_project_id': instance['project_id'],
'port_type': 'NovaVMPort',
'ip6_address': ipv6_address,
}
try:
utils.execute('ip', 'link', 'set', if_remote_name, 'netns',
container_id, run_as_root=True)
result = self._vrouter_client.add_port(
instance['uuid'], vif['id'],
if_local_name, vif['address'], **params)
if not result:
# follow the exception path
raise RuntimeError('add_port returned %s' % str(result))
utils.execute('ip', 'link', 'set', if_local_name, 'up',
run_as_root=True)
except Exception:
LOG.exception("Failed to attach the network")
msg = _('Failed to attach the network, rolling back')
undo_mgr.rollback_and_reraise(msg=msg, instance=instance)
try:
utils.execute('ip', 'netns', 'exec', container_id, 'ip', 'link',
'set', if_remote_name, 'address', vif['address'],
run_as_root=True)
if ipv6_address:
ip = ipv6_address + "/" + ipv6_netmask
gateway = ipv6_gateway
utils.execute('ip', 'netns', 'exec', container_id, 'ifconfig',
if_remote_name, 'inet6', 'add', ip,
run_as_root=True)
utils.execute('ip', 'netns', 'exec', container_id, 'ip', '-6',
'route', 'replace', 'default', 'via', gateway,
#.........这里部分代码省略.........
示例4: VRouterApiTest
# 需要导入模块: from contrail_vrouter_api.vrouter_api import ContrailVRouterApi [as 别名]
# 或者: from contrail_vrouter_api.vrouter_api.ContrailVRouterApi import periodic_connection_check [as 别名]
class VRouterApiTest(unittest.TestCase):
def setUp(self):
self._api = ContrailVRouterApi()
def test_create_port(self):
mock_client = mock.Mock()
self._api._rpc_client_instance = mock.MagicMock(
name='rpc_client_instance')
self._api._rpc_client_instance.return_value = mock_client
self._api.add_port(str(uuid.uuid1()), str(uuid.uuid1()), 'tapX',
'aa:bb:cc:ee:ff:00')
self.assertTrue(mock_client.AddPort.called)
def test_delete_port(self):
mock_client = mock.Mock()
self._api._rpc_client_instance = mock.MagicMock(
name='rpc_client_instance')
self._api._rpc_client_instance.return_value = mock_client
vm_uuid = uuid.uuid1()
vif_uuid = uuid.uuid1()
self._api.add_port(str(vm_uuid), str(vif_uuid), 'tapX',
'aa:bb:cc:ee:ff:00')
self.assertTrue(mock_client.AddPort.called)
self.assertTrue(self._api._ports[vif_uuid])
self._api.delete_port(str(vif_uuid))
self.assertTrue(mock_client.DeletePort.called)
def test_resynchronize(self):
self._api._rpc_client_instance = mock.MagicMock(
name='rpc_client_instance')
self._api._rpc_client_instance.return_value = None
vm_uuid = str(uuid.uuid1())
vif_uuid = str(uuid.uuid1())
port1 = ttypes.Port(self._api._uuid_string_to_hex(vif_uuid),
self._api._uuid_string_to_hex(vm_uuid),
'tapX', '0.0.0.0', [0] * 16, 'aa:bb:cc:ee:ff:00')
self._api.add_port(vm_uuid, vif_uuid, 'tapX', 'aa:bb:cc:ee:ff:00')
mock_client = mock.Mock()
self._api._rpc_client_instance.return_value = mock_client
self._api.periodic_connection_check()
mock_client.AddPort.assert_called_with([port1])
def test_resynchronize_multi_ports(self):
self._api._rpc_client_instance = mock.MagicMock(
name='rpc_client_instance')
self._api._rpc_client_instance.return_value = None
vm_uuid = str(uuid.uuid1())
vif_uuid = str(uuid.uuid1())
port1 = ttypes.Port(self._api._uuid_string_to_hex(vif_uuid),
self._api._uuid_string_to_hex(vm_uuid),
'tapX', '0.0.0.0', [0] * 16, 'aa:bb:cc:ee:ff:00')
self._api.add_port(vm_uuid, vif_uuid, 'tapX', 'aa:bb:cc:ee:ff:00')
vm_uuid = str(uuid.uuid1())
vif_uuid = str(uuid.uuid1())
port2 = ttypes.Port(self._api._uuid_string_to_hex(vif_uuid),
self._api._uuid_string_to_hex(vm_uuid),
'tapY', '0.0.0.0', [0] * 16, '11:22:33:44:55:66')
self._api.add_port(vm_uuid, vif_uuid, 'tapY', '11:22:33:44:55:66')
mock_client = mock.Mock()
self._api._rpc_client_instance.return_value = mock_client
self._api.connect()
self._api._resynchronize()
mock_client.AddPort.assert_called_with([port1, port2])
def test_additional_arguments(self):
mock_client = mock.Mock()
self._api._rpc_client_instance = mock.MagicMock(
name='rpc_client_instance')
self._api._rpc_client_instance.return_value = mock_client
vif_uuid = uuid.uuid1()
network_uuid = uuid.uuid1()
project_id = uuid.uuid1().hex
self._api.add_port(str(uuid.uuid1()), str(vif_uuid), 'tapX',
'aa:bb:cc:ee:ff:00',
network_uuid=str(network_uuid),
vm_project_id=project_id)
self.assertTrue(mock_client.AddPort.called)
port = self._api._ports[vif_uuid]
self.assertEqual(self._api._uuid_to_hex(network_uuid),
port.vn_id)
self.assertEqual(self._api._uuid_string_to_hex(project_id),
port.vm_project_id)
示例5: ContrailInterfaceDriver
# 需要导入模块: from contrail_vrouter_api.vrouter_api import ContrailVRouterApi [as 别名]
# 或者: from contrail_vrouter_api.vrouter_api.ContrailVRouterApi import periodic_connection_check [as 别名]
class ContrailInterfaceDriver(interface.LinuxInterfaceDriver):
""" Opencontrail VIF driver for neutron."""
@classmethod
def _parse_class_args(cls, cfg_parser):
cfg_parser.read(CONTRAIL_CFG_FILE)
cls._api_server_ip = _read_cfg(cfg_parser, 'APISERVER',
'api_server_ip', '127.0.0.1')
cls._api_server_port = _read_cfg(cfg_parser, 'APISERVER',
'api_server_port', '8082')
cls._api_server_use_ssl = _read_cfg(cfg_parser, 'APISERVER',
'use_ssl', False)
def __init__(self, conf):
super(ContrailInterfaceDriver, self).__init__(conf)
self._port_dict = {}
self._client = self._connect_to_api_server()
self._vrouter_client = ContrailVRouterApi()
timer = loopingcall.FixedIntervalLoopingCall(self._keep_alive)
timer.start(interval=2)
def _connect_to_api_server(self):
cfg_parser = ConfigParser.ConfigParser()
ContrailInterfaceDriver._parse_class_args(cfg_parser)
try:
client = VncApi(api_server_host=self._api_server_ip,
api_server_port=self._api_server_port,
api_server_use_ssl=self._api_server_use_ssl)
return client
except:
pass
def _keep_alive(self):
self._vrouter_client.periodic_connection_check()
def _delete_port(self, port_id):
self._vrouter_client.delete_port(port_id)
def _instance_locate(self, port_obj):
""" lookup the instance associated with the port object.
Create the vm instance if port object is not associated
with a vm instance
"""
if port_obj.get_virtual_machine_refs() is not None:
try:
vm_uuid = port_obj.get_virtual_machine_refs()[0]['uuid']
instance_obj = self._client.virtual_machine_read(id=vm_uuid)
return instance_obj
except NoIdError:
pass
vm_uuid = str(uuid.uuid4())
instance_obj = VirtualMachine(vm_uuid)
instance_obj.uuid = vm_uuid
self._client.virtual_machine_create(instance_obj)
port_obj.set_virtual_machine(instance_obj)
self._client.virtual_machine_interface_update(port_obj)
return instance_obj
def _add_port_to_agent(self, port_id, net_id, iface_name, mac_address):
port_obj = self._client.virtual_machine_interface_read(id=port_id)
if port_obj is None:
LOG.debug(_("Invalid port_id : %s"), port_id)
return
ips = port_obj.get_instance_ip_back_refs()
ip_addr = '0.0.0.0'
# get the ip address of the port if associated
if ips and len(ips):
ip_uuid = ips[0]['uuid']
ip = self._client.instance_ip_read(id=ip_uuid)
ip_addr = ip.get_instance_ip_address()
net_obj = self._client.virtual_network_read(id=net_id)
if net_obj is None:
LOG.debug(_("Invalid net_id : %s"), net_id)
return
# get the instance object the port is attached to
instance_obj = self._instance_locate(port_obj)
if instance_obj is None:
return
kwargs = {}
kwargs['ip_address'] = ip_addr
kwargs['network_uuid'] = net_id
kwargs['vm_project_uuid'] = net_obj.parent_uuid
self._vrouter_client.add_port(instance_obj.uuid, port_id, iface_name,
mac_address, **kwargs)
def plug(self, network_id, port_id, device_name, mac_address,
bridge=None, namespace=None, prefix=None):
if not ip_lib.device_exists(device_name, self.root_helper, namespace):
ip = ip_lib.IPWrapper(self.root_helper)
tap_name = device_name.replace(prefix or 'veth', 'veth')
# Create ns_dev in a namespace if one is configured.
root_dev, ns_dev = ip.add_veth(tap_name,
device_name,
#.........这里部分代码省略.........
示例6: VRouterVIFDriver
# 需要导入模块: from contrail_vrouter_api.vrouter_api import ContrailVRouterApi [as 别名]
# 或者: from contrail_vrouter_api.vrouter_api.ContrailVRouterApi import periodic_connection_check [as 别名]
class VRouterVIFDriver(LibVirtVIFDriver):
"""VIF driver for VRouter when running Neutron."""
PORT_TYPE = 'NovaVMPort'
def __init__(self, get_connection):
super(VRouterVIFDriver, self).__init__(get_connection)
self._vrouter_semaphore = eventlet.semaphore.Semaphore()
self._vrouter_client = ContrailVRouterApi(doconnect=True, semaphore=self._vrouter_semaphore)
timer = loopingcall.FixedIntervalLoopingCall(self._keep_alive)
timer.start(interval=2)
def _keep_alive(self):
self._vrouter_client.periodic_connection_check()
@staticmethod
def _get_br_name(dev):
"""Returns the bridge name for a tap device.
This is lxc related stuff. To work around the fact, that libvirt does
not support direct passthrough of devices to LXC."""
return 'br%s' % dev[3:]
def _create_bridge(self, dev, instance):
"""Creating a bridge and returning its name"""
br_name = self._get_br_name(dev)
try:
linux_net.LinuxBridgeInterfaceDriver.ensure_bridge(br_name, dev)
linux_net._execute('ip', 'link', 'set', br_name, 'promisc', 'on',
run_as_root=True)
except processutils.ProcessExecutionError:
LOG.exception(_LE("Failed while plugging vif"), instance=instance)
return br_name
def get_config(self, instance, vif, image_meta, inst_type, virt_type=None):
try:
conf = super(VRouterVIFDriver, self).get_config(instance, vif,
image_meta, inst_type)
except TypeError:
conf = super(VRouterVIFDriver, self).get_base_config(instance, vif,
image_meta, inst_type, virt_type)
dev = self.get_vif_devname(vif)
if not virt_type:
try:
virt_type = cfg.CONF.libvirt.virt_type
except cfg.NoSuchOptError:
virt_type = cfg.CONF.libvirt_type
if virt_type == 'lxc':
# for lxc we need to pass a bridge to libvirt
br_name = self._get_br_name(dev)
designer.set_vif_host_backend_bridge_config(conf, br_name)
else:
if CONF.contrail.use_userspace_vhost:
dev = path.join(CONF.contrail.userspace_vhost_socket_dir,
'uvh_vif_' + dev)
designer.set_vif_host_backend_vhostuser_config(conf, 'client',
dev)
else:
designer.set_vif_host_backend_ethernet_config(conf, dev)
designer.set_vif_bandwidth_config(conf, inst_type)
return conf
def plug(self, instance, vif):
try:
dev = self.get_vif_devname(vif)
try:
if not CONF.contrail.use_userspace_vhost:
linux_net.create_tap_dev(dev)
except processutils.ProcessExecutionError:
LOG.exception(_LE("Failed while plugging vif"), instance=instance)
try:
virt_type = cfg.CONF.libvirt.virt_type
except cfg.NoSuchOptError:
virt_type = cfg.CONF.libvirt_type
if virt_type == 'lxc':
dev = self._create_bridge(dev, instance)
ipv4_address = '0.0.0.0'
ipv6_address = None
subnets = vif['network']['subnets']
for subnet in subnets:
ips = subnet['ips'][0]
if (ips['version'] == 4):
if ips['address'] is not None:
ipv4_address = ips['address']
if (ips['version'] == 6):
if ips['address'] is not None:
ipv6_address = ips['address']
kwargs = {
'ip_address': ipv4_address,
'vn_id': vif['network']['id'],
'display_name': instance['display_name'],
'hostname': instance['hostname'],
#.........这里部分代码省略.........
示例7: VRouterVIFDriver
# 需要导入模块: from contrail_vrouter_api.vrouter_api import ContrailVRouterApi [as 别名]
# 或者: from contrail_vrouter_api.vrouter_api.ContrailVRouterApi import periodic_connection_check [as 别名]
class VRouterVIFDriver(LibvirtBaseVIFDriver):
"""VIF driver for VRouter when running Neutron."""
PORT_TYPE = 'NovaVMPort'
def __init__(self, get_connection):
super(VRouterVIFDriver, self).__init__(get_connection)
self._vrouter_client = ContrailVRouterApi()
timer = loopingcall.FixedIntervalLoopingCall(self._keep_alive)
timer.start(interval=2)
def _keep_alive(self):
self._vrouter_client.periodic_connection_check()
@staticmethod
def _get_br_name(dev):
"""Returns the bridge name for a tap device.
This is lxc related stuff. To work around the fact, that libvirt does
not support direct passthrough of devices to LXC."""
return 'br%s' % dev[3:]
def _create_bridge(self, dev, instance):
"""Creating a bridge and returning its name"""
br_name = self._get_br_name(dev)
try:
linux_net.LinuxBridgeInterfaceDriver.ensure_bridge(br_name, dev)
linux_net._execute('ip', 'link', 'set', br_name, 'promisc', 'on',
run_as_root=True)
except processutils.ProcessExecutionError:
LOG.exception(_LE("Failed while plugging vif"), instance=instance)
return br_name
def get_config(self, instance, vif, image_meta, inst_type):
conf = super(VRouterVIFDriver, self).get_config(instance, vif,
image_meta, inst_type)
dev = self.get_vif_devname(vif)
if cfg.CONF.libvirt.virt_type == 'lxc':
# for lxc we need to pass a bridge to libvirt
br_name = self._get_br_name(dev)
designer.set_vif_host_backend_bridge_config(conf, br_name)
else:
designer.set_vif_host_backend_ethernet_config(conf, dev)
designer.set_vif_bandwidth_config(conf, inst_type)
return conf
def plug(self, instance, vif):
dev = self.get_vif_devname(vif)
try:
linux_net.create_tap_dev(dev)
except processutils.ProcessExecutionError:
LOG.exception(_LE("Failed while plugging vif"), instance=instance)
if cfg.CONF.libvirt.virt_type == 'lxc':
dev = self._create_bridge(dev, instance)
kwargs = {
'ip_address': vif['network']['subnets'][0]['ips'][0]['address'],
'vn_id': vif['network']['id'],
'display_name': instance['display_name'],
'hostname': instance['hostname'],
'host': instance['host'],
'vm_project_id': instance['project_id'],
'port_type': self.PORT_TYPE,
}
try:
result = self._vrouter_client.add_port(instance['uuid'],
vif['id'],
dev,
vif['address'],
**kwargs)
if not result:
LOG.exception(_LE("Failed while plugging vif"),
instance=instance)
except TApplicationException:
LOG.exception(_LE("Failed while plugging vif"), instance=instance)
def unplug(self, instance, vif):
dev = self.get_vif_devname(vif)
try:
self._vrouter_client.delete_port(vif['id'])
#delegate the deletion of tap device to a deffered thread
worker_thread = threading.Thread(target=self.delete_device, \
name='contrailvif', args=(dev,))
worker_thread.start()
except (TApplicationException, processutils.ProcessExecutionError,\
RuntimeError):
LOG.exception(_LE("Failed while unplugging vif"),
instance=instance)
def delete_device(self, dev):
time.sleep(2)
LOG.debug(dev)
if cfg.CONF.libvirt.virt_type == 'lxc':
linux_net.LinuxBridgeInterfaceDriver.remove_bridge(
self._get_br_name(dev))
#.........这里部分代码省略.........
示例8: VRouterApiTest
# 需要导入模块: from contrail_vrouter_api.vrouter_api import ContrailVRouterApi [as 别名]
# 或者: from contrail_vrouter_api.vrouter_api.ContrailVRouterApi import periodic_connection_check [as 别名]
class VRouterApiTest(unittest.TestCase):
def setUp(self):
self._api = ContrailVRouterApi()
def test_create_port(self):
mock_client = mock.Mock()
self._api._rpc_client_instance = mock.MagicMock(
name='rpc_client_instance')
self._api._rpc_client_instance.return_value = mock_client
self._api.add_port(str(uuid.uuid1()), str(uuid.uuid1()), 'tapX',
'aa:bb:cc:ee:ff:00')
self.assertTrue(mock_client.AddPort.called)
def test_delete_port(self):
mock_client = mock.Mock()
self._api._rpc_client_instance = mock.MagicMock(
name='rpc_client_instance')
self._api._rpc_client_instance.return_value = mock_client
vm_uuid = uuid.uuid1()
vif_uuid = uuid.uuid1()
self._api.add_port(str(vm_uuid), str(vif_uuid), 'tapX',
'aa:bb:cc:ee:ff:00')
self.assertTrue(mock_client.AddPort.called)
self.assertTrue(self._api._ports[vif_uuid])
self._api.delete_port(str(vif_uuid))
self.assertTrue(mock_client.DeletePort.called)
def test_resynchronize(self):
self._api._rpc_client_instance = mock.MagicMock(
name='rpc_client_instance')
self._api._rpc_client_instance.return_value = None
vm_uuid = str(uuid.uuid1())
vif_uuid = str(uuid.uuid1())
self._api.add_port(vm_uuid, vif_uuid, 'tapX', 'aa:bb:cc:ee:ff:00')
mock_client = mock.Mock()
self._api._rpc_client_instance.return_value = mock_client
self._api.periodic_connection_check()
self.assertTrue(mock_client.AddPort.called)
def test_additional_arguments(self):
mock_client = mock.Mock()
self._api._rpc_client_instance = mock.MagicMock(
name='rpc_client_instance')
self._api._rpc_client_instance.return_value = mock_client
vif_uuid = uuid.uuid1()
network_uuid = uuid.uuid1()
project_uuid = uuid.uuid1()
self._api.add_port(str(uuid.uuid1()), str(vif_uuid), 'tapX',
'aa:bb:cc:ee:ff:00',
network_uuid=str(network_uuid),
vm_project_uuid=str(project_uuid))
self.assertTrue(mock_client.AddPort.called)
port = self._api._ports[vif_uuid]
self.assertEqual(self._api._uuid_to_hex(network_uuid),
port.vn_id)
self.assertEqual(self._api._uuid_to_hex(project_uuid),
port.vm_project_uuid)