Exemplo n.º 1
0
    def connect(self):
        """
        Connects to the SQL Server instance using specified credentials
        :return: OwnerUri if connection established else None
        """
        if self.is_connected:
            return self.owner_uri

        # Required params
        connection_params = {u'ServerName': self.server_name,
                             u'DatabaseName': self.database,
                             u'UserName': self.user_name,
                             u'Password': self.password,
                             u'AuthenticationType': self.authentication_type,
                             u'OwnerUri': self.owner_uri,
                             u'MultipleActiveResultSets': self.multiple_active_result_sets}

        # Optional params
        if self.encrypt:
            connection_params[u'Encrypt'] = self.encrypt
        if self.trust_server_certificate:
            connection_params[u'TrustServerCertificate'] = self.trust_server_certificate
        if self.connection_timeout:
            connection_params[u'ConnectTimeout'] = self.connection_timeout
        if self.application_intent:
            connection_params[u'ApplicationIntent'] = self.application_intent
        if self.multi_subnet_failover:
            connection_params[u'MultiSubnetFailover'] = self.multi_subnet_failover
        if self.packet_size:
            connection_params[u'PacketSize'] = self.packet_size

        connection_params.update(self.extra_params)

        connection_request = self.sql_tools_client.create_request(
            u'connection_request', connection_params)
        connection_request.execute()

        while not connection_request.completed():
            response = connection_request.get_response()
            if response:
                response = connectionservice.handle_connection_response(
                    response)
            else:
                time.sleep(time_wait_if_no_response)

        if response and response.connection_id:
            # response owner_uri should be the same as owner_uri used, else
            # something is weird :)
            assert response.owner_uri == self.owner_uri
            self.is_connected = True
            self.server_version = response.server_version
            self.server_edition = response.server_edition
            self.is_cloud = response.is_cloud

            logger.info(
                u'Connection Successful. Connection Id {0}'.format(
                    response.connection_id))
            return self.owner_uri
Exemplo n.º 2
0
    def verify_success_response(self, request):
        response_event = 0
        complete_event = 0
        request.execute()
        time.sleep(1)

        while not request.completed():
            response = request.get_response()
            if response:
                if isinstance(response, connectionservice.ConnectionResponse):
                    response_event += 1
                elif isinstance(response,
                                connectionservice.ConnectionCompleteEvent):
                    if response.connection_id:
                        complete_event += 1
                        self.assertTrue(
                            connectionservice.handle_connection_response(
                                response).connection_id,
                            response.connection_id)

        self.assertEqual(response_event, 1)
        self.assertEqual(complete_event, 1)