def test_new_interface_becomes_visible():
    """
    Title: Test new interface becomes visible

    Scenario:
    When: On start up, a Midolman sees no interface,
    Then: adds a new interface,
    And: Midolman detects a new interface.
    """

    # FIXME: pick the midonet-agent from binding manager (when parallel)
    midonet_api = get_midonet_api()
    agent = service.get_container('midonet-agent', 1)
    iface_name = 'interface%d' % random.randint(1, 100)
    new_interface = get_interface(
        midonet_api,
        agent.get_midonet_host_id(),
        iface_name)
    # Test that no interface with name 'interface_01' exists.
    assert_that(new_interface, none(), iface_name)

    # Create a new interface 'interface_01'.
    iface = agent.create_vmguest(ifname=iface_name)
    time.sleep(5)
    new_interface = get_interface(
        midonet_api,
        agent.get_midonet_host_id(),
        iface_name)

    # Test that the created interface is visible.
    assert_that(new_interface, not_none(), iface_name)

    agent.destroy_vm(iface)
Пример #2
0
    def bind(self, filename=None, data=None):
        # Build a new virtual topology at every binding, destroy at the end
        self._ptm.build()
        self._vtm.build()

        self._data = self._get_data(filename, data)
        # Get a new api ref to workaround previous zk failures
        self._api = get_midonet_api()

        bindings = self._data['bindings']
        for b in bindings:
            binding = b['binding']

            host_id = binding['host_id']
            iface_id = binding['interface_id']
            device_name = binding['device_name']
            port_id = binding['port_id']

            self._port_if_map[(device_name, port_id)] = \
                (host_id, iface_id)

            device_port = self._vtm.get_device_port(device_name, port_id)
            mn_vport = device_port._mn_resource
            if mn_vport.get_type() == 'InteriorRouter' or \
               mn_vport.get_type() == 'InteriorBridge':
                LOG.error("Cannot bind interior port")
                sys.exit(-1) # TODO: make this fancier

            mn_vport_id = mn_vport.get_id()
            host = service.get_container('midolman', host_id)

            # Clean up yamls or remove them completely, this is so ugly
            _host = filter(
                lambda x: x['host']['id'] == host_id,
                self._ptm._hosts)[0]['host']
            _interface = filter(
                lambda x: x['interface']['id'] == iface_id,
                _host['interfaces']
            )[0]['interface']

            # Remove kwargs we are not interested in
            _interface_vm = dict(_interface)
            del _interface_vm['ipv6_addr']
            del _interface_vm['type']
            del _interface_vm['id']

            iface = host.create_vmguest(**_interface_vm)
            self._port_if_map[(device_name, port_id)] = iface
            iface.vport_id = mn_vport_id
            self._vms.append(iface)
            iface.clear_arp(sync=True)
            iface_name = iface.get_host_ifname()
            #iface.interface['ifname']
            mn_host_id = host.get_midonet_host_id()
            #iface.host['mn_host_id']
            iface.vport_id = mn_vport_id
            host.bind_port(iface, mn_vport_id)
            await_port_active(mn_vport_id)
Пример #3
0
    def build(self):
        """
        Build physical topology from the data.

        Args:
            filename: filename that defines physical topology
            data: python dictionary object to represent the physical topology

        """

        LOG.debug('-' * 80)
        LOG.debug("build")
        LOG.debug('-' * 80)
        #for b in self._bridges:
        #    bridge = b['bridge']
        #    # TODO(tomohiko) Need to something when not bridge['provided']?
        #    if bridge['provided']:
        #        LOG.info('Skipped building bridge=%r', bridge)

        hosts = service.get_all_containers('midolman')
        midonet_api_host = service.get_container('midonet-api')
        midonet_api = midonet_api_host.get_midonet_api()

        if is_vxlan_enabled():
            tz = midonet_api.add_vxlan_tunnel_zone()
        else:
            tz = midonet_api.add_gre_tunnel_zone()
            tz.name('mdts-test')
            tz.create()

        for host in hosts:
            tz_host = tz.add_tunnel_zone_host()
            tz_host.ip_address(host.get_ip_address())
            tz_host.host_id(host.get_midonet_host_id())
            tz_host.create()

        # for h in self._hosts:
        #     host = h['host']
        #     host_container = service.load_from_name('midonet-agent.'+host['id'])
        #     if host.get('tunnel_zone'):
        #         tz_data = host.get('tunnel_zone')
        #         tzs = self._api.get_tunnel_zones()
        #
        #         # Ensure that TZ exists
        #         tz = [t for t in tzs if t.get_name() == tz_data['name']]
        #         if tz == []:
        #             if is_vxlan_enabled():
        #                 tz = self._api.add_vxlan_tunnel_zone()
        #             else:
        #                 tz = self._api.add_gre_tunnel_zone()
        #             tz.name(tz_data['name'])
        #             tz.create()
        #         else:
        #             tz = tz[0]
        #
        #         # Ensure that the host is in the TZ
        #         tz_hosts = tz.get_hosts()
        #         tz_host = filter(
        #             lambda x: x.get_host_id() == host['mn_host_id'],
        #             tz_hosts)
        #         if tz_host == []:
        #             tz_host = tz.add_tunnel_zone_host()
        #             tz_host.ip_address(tz_data['ip_addr'])
        #             tz_host.host_id(host['mn_host_id'])
        #             tz_host.create()

            #if host['provided'] == True:
            #    LOG.info('Skipped building host=%r', host)
            #else:
            #    #TODO(tomoe): when we support provisioning Midolman host with
            #    # this tool.
            #    pass
            #interfaces = host['interfaces']

            #futures = []
            #for i in interfaces:
            #    iface = Interface(i['interface'], host)
            #    self._interfaces[(host['id'], i['interface']['id'])] = iface
            #    f = iface.create()
            #    futures.append(f)

            #wait_on_futures(futures)

        LOG.debug('-' * 80)
        LOG.debug("end build")
        LOG.debug('-' * 80)
Пример #4
0
 def __init__(self, service_type, id=1):
     super(ServiceFailure, self).__init__("%s failure" % service_type)
     self.service_type = service_type
     self.service = service.get_container(service_type, id)
Пример #5
0
 def get_api(self):
     if not self.api:
         self.api = service.get_container('midonet-api').get_midonet_api()
     return self.api