def stop_auto_stop_candidates(): autoStopCandidates = ec2.get_auto_stop_candidates() instanceIdsToStop = [] for instance in autoStopCandidates: instanceIdsToStop.append(instance['id']) ec2.stop(instanceIdsToStop)
def test_stop_not_called_when_reqeusted_ids_is_empty(self, mock_landlord, mock_ec2): instances = [] mock_landlord.Tenant = StubLandlord mock_connection = Mock() mock_ec2.connect_to_region.return_value = mock_connection ec2.stop(instances) self.assertEquals(mock_ec2.connect_to_region.call_count, 0); self.assertEquals(mock_connection.stop_instances.call_count, 0);
def test_tag_added_when_instance_auto_stopped(self, mock_landlord, mock_ec2): instances = ['i-278219', 'i-82715'] mock_landlord.Tenant = StubLandlord mock_connection = Mock() mock_ec2.connect_to_region.return_value = mock_connection mockInstance1 = Mock() mockInstance2 = Mock() mock_connection.stop_instances.return_value = [mockInstance1, mockInstance2] ec2.stop(instances) mockInstance1.add_tags.assert_called_with({'AutoStopped': 'True'}) mockInstance2.add_tags.assert_called_with({'AutoStopped': 'True'})
def test_stop_reqeusted_for_ids(self, mock_landlord, mock_ec2): instances = ['i-278219', 'i-82715'] mock_landlord.Tenant = StubLandlord mock_connection = Mock() mock_ec2.connect_to_region.return_value = mock_connection mockInstance1 = Mock() mockInstance2 = Mock() mock_connection.stop_instances.return_value = [mockInstance1, mockInstance2] ec2.stop(instances) mock_ec2.connect_to_region.assert_called_with('deploy.region', aws_access_key_id='aws.id', aws_secret_access_key='aws.secret') mock_connection.stop_instances.assert_called_with(instances)