Exemple #1
0
	def test_network_config_discover(self):
		send_socket = self._create_fake_send_socket()
		recv_socket = self._create_fake_receive_socket(DiscoveryNetworkConfigResponseBytes)

		d = Discovery()
		d._create_send_socket = Mock(return_value=send_socket)
		d._create_receive_socket = Mock(return_value=recv_socket)

		response = d.discover("KEQ0523864", Discovery.DISCOVERY_TYPE_NETWORK_CONFIG)
		send_socket.sendto.assert_called_with(DiscoveryNetworkConfigRequestBytes, ("255.255.255.255", 23272))
		self.assertEqual(response, DiscoveryNetworkConfigurationResponse(DiscoveryNetworkConfigResponseBytes))

		self.assertTrue(send_socket.close.called)
		self.assertTrue(recv_socket.close.called)
Exemple #2
0
	def test_identify_discover(self):
		send_socket = self._create_fake_send_socket()
		recv_socket = self._create_fake_receive_socket(DiscoveryIdentifyResponseBytes)

		d = Discovery()
		d._create_send_socket = Mock(return_value=send_socket)
		d._create_receive_socket = Mock(return_value=recv_socket)

		response = d.discover()
		send_socket.sendto.assert_called_with(DiscoveryIdentifyRequestBytes, ("255.255.255.255", 23272))
		self.assertEqual(response, DiscoveryIdentifyResponse(DiscoveryIdentifyResponseBytes))

		self.assertTrue(send_socket.close.called)
		self.assertTrue(recv_socket.close.called)
Exemple #3
0
    def test_identify_discover(self):
        send_socket = self._create_fake_send_socket()
        recv_socket = self._create_fake_receive_socket(
            DiscoveryIdentifyResponseBytes)

        d = Discovery()
        d._create_send_socket = Mock(return_value=send_socket)
        d._create_receive_socket = Mock(return_value=recv_socket)

        response = d.discover()
        send_socket.sendto.assert_called_with(DiscoveryIdentifyRequestBytes,
                                              ("255.255.255.255", 23272))
        self.assertEqual(
            response,
            DiscoveryIdentifyResponse(DiscoveryIdentifyResponseBytes))

        self.assertTrue(send_socket.close.called)
        self.assertTrue(recv_socket.close.called)
Exemple #4
0
    def test_network_config_discover(self):
        send_socket = self._create_fake_send_socket()
        recv_socket = self._create_fake_receive_socket(
            DiscoveryNetworkConfigResponseBytes)

        d = Discovery()
        d._create_send_socket = Mock(return_value=send_socket)
        d._create_receive_socket = Mock(return_value=recv_socket)

        response = d.discover("KEQ0523864",
                              Discovery.DISCOVERY_TYPE_NETWORK_CONFIG)
        send_socket.sendto.assert_called_with(
            DiscoveryNetworkConfigRequestBytes, ("255.255.255.255", 23272))
        self.assertEqual(
            response,
            DiscoveryNetworkConfigurationResponse(
                DiscoveryNetworkConfigResponseBytes))

        self.assertTrue(send_socket.close.called)
        self.assertTrue(recv_socket.close.called)
Exemple #5
0
if __name__ == "__main__":  # pragma: no cover
    parser = ArgumentParser()
    parser.add_argument('-v', '--verbose', action="count", default=1)
    parser.add_argument('-s', '--serial', help='Query cube with serial')
    parser.add_argument('host', nargs='?')

    args = parser.parse_args()

    logging.basicConfig(level=logging.FATAL - (10 * args.verbose),
                        format='%(asctime)s %(levelname)-7s %(message)s')

    host = args.host
    if not host:
        serial = args.serial
        if not serial:
            response = Discovery().discover()
            if response:
                serial = response.serial
            else:
                print("No cubes found.")
                sys.exit(1)

        try:
            net_cfg_response = Discovery().discover(
                cube_serial=serial,
                discovery_type=Discovery.DISCOVERY_TYPE_NETWORK_CONFIG)
            print("Discovered cube: %s" % net_cfg_response)
            host = net_cfg_response.ip_address
        except socket.timeout as st:
            print("Could not find cube '%s': %s" % (serial, st))
            sys.exit(1)