def test_delete(self):
        # arrange
        uuid = "uuid"
        network_name = "network_name"

        network = Mock()
        network.name = network_name
        si = Mock()
        vm = Mock()
        vm.network = [network]

        connection_detail = Mock()
        connection_detail.host = Mock()
        connection_detail.username = Mock()
        connection_detail.password = Mock()
        connection_detail.port = Mock()

        pv_service = Mock()
        pv_service.connect = Mock(return_value=si)
        pv_service.find_by_uuid = Mock(return_value=vm)

        connector = VirtualSwitchToMachineDisconnectCommand(pv_service, Mock(), "anetwork")

        # act
        res = connector.disconnect(si, uuid, network_name)

        # assert
        self.assertTrue(
            pv_service.connect.called_with(
                connection_detail.host, connection_detail.username, connection_detail.password, connection_detail.port
            )
        )
        self.assertTrue(pv_service.find_by_uuid.called_with(si, uuid))
        self.assertTrue(res)
    def test_delete_all(self):
        # arrange
        uuid = "uuid"
        si = Mock()
        vm = Mock()

        connection_detail = Mock()
        connection_detail.host = Mock()
        connection_detail.username = Mock()
        connection_detail.password = Mock()
        connection_detail.port = Mock()

        pv_service = Mock()
        pv_service.connect = Mock(return_value=si)
        pv_service.find_by_uuid = Mock(return_value=vm)

        connector = VirtualSwitchToMachineDisconnectCommand(pv_service, Mock(), "anetwork")
        # virtual_switch_to_machine_connector.remove_interfaces_from_vm = Mock(return_value=True)
        connector.get_network_by_name = lambda x, y: Mock()

        vcenter_data_model = VMwarevCenterResourceModel()

        # act
        res = connector.disconnect(
            si=si, logger=Mock(), vcenter_data_model=vcenter_data_model, vm_uuid=uuid, network_name=None, vm=None
        )
        # assert
        self.assertTrue(
            pv_service.connect.called_with(
                connection_detail.host, connection_detail.username, connection_detail.password, connection_detail.port
            )
        )
        self.assertTrue(pv_service.find_by_uuid.called_with(si, uuid))
        # self.assertTrue(virtual_switch_to_machine_connector.remove_interfaces_from_vm.called_with(vm))
        self.assertTrue(res)
Example #3
0
 def _get_mock_segment(self, name, datadir, port, hostname, address):
     m = Mock()
     m.name = name
     m.datadir = datadir
     m.port = port
     m.hostname = hostname
     m.address = address
     return m
Example #4
0
 def test_release_connection(self):
     conn = Mock()
     conn.host = "foo"
     conn.port = 9
     mypool = pool.ShardPool(self.servers)
     mypool._in_use_connections["foo:9"].add(conn)
     self.assertTrue(mypool._in_use_connections["foo:9"])
     mypool.release(conn)
     self.assertFalse(mypool._in_use_connections["foo:9"])
Example #5
0
def create_fake_endpoint(name="source", **kw):
    ep = Mock()
    ep.zone.name = name
    ep.secret_key = kw.get("secret", "secret")
    ep.access_key = kw.get("access", "access")
    ep.port = kw.get("port", 7777)
    ep.host = kw.get("host", "localhost")
    ep.debug = kw.get("debug", True)
    return ep
Example #6
0
def _get_conn(reader):
    global _conn_port
    conn = Mock()
    conn.host = "localhost"
    conn.port = _conn_port
    _conn_port += 1
    reader._initialize_conn(conn)
    reader._conn_subscribe(conn)
    return conn
Example #7
0
 def test_get_db_params_returns_args_parameters(self, mock_parse_config_file):
     mock_parse_config_file.return_value = (None, None, None)
     mock_args = Mock()
     mock_args.host = "pumpkin"
     mock_args.port = 12345
     mock_args.index = "ciccio"
     elasticsearch_url, elasticsearch_index = get_db_params(mock_args)
     self.assertEquals(elasticsearch_url, "http://pumpkin:12345")
     self.assertEquals(elasticsearch_index, "ciccio")
 def test_by_address_with_srv(self):
     with patch("dns.resolver.query") as query:
         answer = Mock()
         answer.target = "different.example.org."
         answer.port = 12345
         query.return_value = [answer]
         self.server = MinecraftServer.lookup("example.org")
         query.assert_called_once_with("_minecraft._tcp.example.org", "SRV")
     self.assertEqual(self.server.host, "different.example.org")
     self.assertEqual(self.server.port, 12345)
Example #9
0
    def _get_registered_scheduler_driver_master(self):
        driver = Mock()
        framework_id = Mock()
        framework_id.value = "framework_id"
        master_info = Mock()
        master_info.hostname = "localhost"
        master_info.port = 1234

        my_scheduler = scheduler.scale_scheduler.ScaleScheduler(None)
        my_scheduler.registered(driver, framework_id, master_info)
        return my_scheduler, driver, master_info
Example #10
0
def dns_query(name, _):
    if "-server" not in name or "-ssl" in name:
        return []
    if name == "_etcd-server._tcp.blabla":
        return []
    elif name == "_etcd-server._tcp.exception":
        raise DNSException()
    srv = Mock()
    srv.port = 2380
    srv.target.to_text.return_value = "localhost" if name == "_etcd-server._tcp.foobar" else "127.0.0.1"
    return [srv]
    def test_is_device_match_network_port_type(self):
        # arrange
        backing = Mock(spec=[])
        device = Mock()
        port = Mock()

        device.backing = backing
        backing.port = port
        port.portgroupKey = "port key"

        # act
        res = VNicService.device_is_attached_to_network(device, port.portgroupKey)

        # assert
        self.assertTrue(res)
Example #12
0
    def add_broker(self, host, port, responses=[], connect_error=None):
        conn = Mock()
        conn.host = host
        conn.port = port
        conn.closing = False

        if connect_error:
            conn.connect.return_value = self.future_error(connect_error)
        else:
            conn.connect.return_value = self.future_value(None)

        @gen.coroutine
        def get_next_response(req):
            log.debug("sent to %s:%s: %s", host, port, req)
            self.sent[(host, port)].append(req)
            raise gen.Return(responses.pop(0))

        conn.send.side_effect = get_next_response

        self.broker_hosts[(host, port)] = conn
Example #13
0
def test_available_ports():
    """
    Test ``available_ports`` filters out ports that are in use by
    ``MOCK_SERVERS``.
    """
    handler = SmtpHandler()
    ports = handler.available_ports()

    assert_equals(ports, PRETEND_PORT_RANGE)

    mock_port = list(PRETEND_PORT_RANGE)[2]
    assert_true(mock_port in ports)
    # Now add a mock server

    pretend_server = Mock()
    pretend_server.port = mock_port
    handler.PRETENDERS[1] = pretend_server

    # Now they should not be equal
    ports = handler.available_ports()

    assert_not_equals(ports, PRETEND_PORT_RANGE)

    assert_false(mock_port in ports)
Example #14
0
    def test_port_property(self):
        mock = Mock(spec=network.Connection)
        mock.port = sentinel.port

        lineprotocol = network.LineProtocol(mock)
        self.assertEqual(sentinel.port, lineprotocol.port)