예제 #1
0
    def testUnmapTerminatedInstancesFromServiceShouldDoNothingIfAllRegisteredInstancesWouldBeDeregistered(
            self):
        # Mock Cloud Map client
        self.sdStubber.add_response(
            "list_instances", {
                "Instances": [
                    mockServiceInstance("i-1", "172.0.0.1"),
                    mockServiceInstance("i-2", "2.2.2.2")
                ]
            }, {
                "ServiceId": "srv-1",
                "MaxResults": 100
            })

        # Mock EC2 client
        self.ec2Stubber.add_response(
            "describe_instances", {"Reservations": []}, {
                "Filters": [{
                    "Name": "instance-id",
                    "Values": ["i-1", "i-2"]
                }],
                "MaxResults": 1000
            })

        with patch("boto3.client", side_effect=self.botoClientMock):
            unmapTerminatedInstancesFromService(serviceId="srv-1",
                                                serviceRegion="eu-west-1",
                                                instancesRegions=["eu-west-1"])

        self.ec2Stubber.assert_no_pending_responses()
        self.sdStubber.assert_no_pending_responses()
예제 #2
0
    def testUnmapTerminatedInstancesFromServiceShouldSupportMultipleInstancesRegions(
            self):
        # Mock Cloud Map client
        self.sdStubber.add_response(
            "list_instances", {
                "Instances": [
                    mockServiceInstance("i-1", "172.0.0.1"),
                    mockServiceInstance("i-2", "2.2.2.2"),
                    mockServiceInstance("i-3", "3.3.3.3")
                ]
            }, {
                "ServiceId": "srv-1",
                "MaxResults": 100
            })
        self.sdStubber.add_response("deregister_instance", {}, {
            "ServiceId": "srv-1",
            "InstanceId": "i-3"
        })

        # Mock EC2 client
        self.ec2Stubber.add_response(
            "describe_instances", {
                "Reservations": [{
                    "Instances":
                    [mockEC2Instance("i-1", privateIp="172.0.0.1")]
                }]
            }, {
                "Filters": [{
                    "Name": "instance-id",
                    "Values": ["i-1", "i-2", "i-3"]
                }],
                "MaxResults":
                1000
            })
        self.ec2Stubber.add_response(
            "describe_instances", {
                "Reservations": [{
                    "Instances": [mockEC2Instance("i-2", publicIp="2.2.2.2")]
                }]
            }, {
                "Filters": [{
                    "Name": "instance-id",
                    "Values": ["i-1", "i-2", "i-3"]
                }],
                "MaxResults":
                1000
            })

        with patch("boto3.client", side_effect=self.botoClientMock):
            unmapTerminatedInstancesFromService(
                serviceId="srv-1",
                serviceRegion="eu-west-1",
                instancesRegions=["eu-west-1", "us-east-1"])

        self.ec2Stubber.assert_no_pending_responses()
        self.sdStubber.assert_no_pending_responses()