def test_non_existing_network(self): try: network.get_ip_of_interface("non_existing_network") self.fail( msg= "get_ip_of_interface has to throw a NetworkException if the given network does not exist" ) except errors.NetworkException: pass
def create_new_swarm(self, advertise_address, interface, predefined_uuid=None): """ RPC method for creating a new swarm :param advertise_address: Advertise address of the host :param interface: Interface of the host :param predefined_uuid: Predefined UUID of the new swarm :return: swarm object as json """ llogger = local_logger.LocalLogger() llogger.log_method_call(self.__class__.__name__, sys._getframe().f_code.co_name) if self._master is not None: llogger.debug("Tried to initialize master twice. Aborting.") raise RuntimeError("Tried to initialize master twice. Aborting.") llogger.debug("Create new swarm on %s", advertise_address) host_ip = network.get_ip_of_interface(self._interface) pyro_nameservice = Pyro4.locateNS(host=host_ip, port=9090, broadcast=False) uri = self._pyro_daemon.register( swarm_engine_master.Master(interface, advertise_address)) pyro_nameservice.register(SWARMROB_MASTER_IDENTIFIER, uri) self._master = Pyro4.Proxy(uri) self._master.start_remote_logging_server() try: return jsonpickle.encode( self._swarm_engine.create_new_swarm( self._master, predefined_uuid=predefined_uuid)) except DockerException: raise RuntimeError(traceback.format_exc())
def test_docker_network(self): try: ip = network.get_ip_of_interface("docker0") self.assertIsNotNone(ip, msg="docker0 network has no ip address") except errors.NetworkException: self.fail( msg= "docker0 network does not exist. Make sure docker is installed" )
def test_local_network(self): try: ip = network.get_ip_of_interface("lo") self.assertEqual( ip, "127.0.0.1", msg="lo network does not have the ip address 127.0.0.1") except errors.NetworkException: self.fail(msg="lo network does not exist")
def test_none(self): try: network_info = network.NetworkInfo(None) default_interface = network.get_default_interface() self.assertEqual(network_info.interface, default_interface) self.assertEqual(network_info.ip_address, network.get_ip_of_interface(default_interface)) except errors.NetworkException: self.fail(msg="Unable to create default network info object")
def get_swarm_status_as_json(self): """ Get the swarm status as JSON :return: swarm as json """ llogger = local_logger.LocalLogger() llogger.log_method_call(self.__class__.__name__, sys._getframe().f_code.co_name) host_ip = network.get_ip_of_interface(self._interface) ns = Pyro4.locateNS(host=str(host_ip)) master_uri = ns.lookup(SWARMROB_MASTER_IDENTIFIER) proxy = Pyro4.Proxy(master_uri) return proxy.get_swarm_status_as_json()
def __init__(self, swarm_uuid, interface): """ Initialization method of a worker object :param swarm_uuid: uuid of the swarm the worker is assigned to :param interface: the interface the worker should listen on """ llogger = local_logger.LocalLogger() llogger.log_method_call(self.__class__.__name__, sys._getframe().f_code.co_name) self._advertise_address = network.get_ip_of_interface(interface) self._interface = interface self._hostname = socket.gethostname() self._uuid = uuid.uuid4().hex self._swarm_uuid = swarm_uuid self._remote_logger = None self._container_list = docker_container_list.DockerContainerList()
def test_none(self): try: network.get_ip_of_interface(None) self.fail(msg="None has to throw a NetworkException") except errors.NetworkException: pass