def main(): parser = argparse.ArgumentParser() parser.add_argument("-r", "--region", dest="regions", action="append", help="optional list of regions") parser.add_argument("-q", "--quiet", action="store_true", help="Supress logging messages") parser.add_argument("-j", "--concurrency", type=int, default=4) args = parser.parse_args() logging.basicConfig(format="%(asctime)s - %(levelname)s - %(message)s") if not args.quiet: log.setLevel(logging.DEBUG) else: log.setLevel(logging.ERROR) logging.getLogger("boto").setLevel(logging.CRITICAL) if not args.regions: args.regions = DEFAULT_REGIONS instances_to_tag = [] for r in args.regions: instances_to_tag.extend(get_instances_to_tag(r)) if instances_to_tag: populate_spot_requests_cache( r, [i.spot_instance_request_id for i in instances_to_tag]) for i in instances_to_tag: log.debug("tagging %s", i) copy_spot_request_tags(i)
def test_invalid_request_id(conn): req = mock.Mock() req.id = "id-1" conn.return_value.get_all_spot_instance_requests.side_effect = \ [boto.exception.EC2ResponseError("404", "reason"), [req]] populate_spot_requests_cache("r-1", ["id-1"]) expected_calls = [mock.call(request_ids=["id-1"]), mock.call()] conn.return_value.get_all_spot_instance_requests.assert_has_calls( expected_calls) assert cloudtools.aws.spot._spot_requests == {("r-1", "id-1"): req}
def test_invalid_request_id(conn): req = mock.Mock() req.id = "id-1" conn.return_value.get_all_spot_instance_requests.side_effect = \ [boto.exception.EC2ResponseError("404", "reason"), [req]] populate_spot_requests_cache("r-1", ["id-1"]) expected_calls = [ mock.call(request_ids=["id-1"]), mock.call() ] conn.return_value.get_all_spot_instance_requests.assert_has_calls( expected_calls) assert cloudtools.aws.spot._spot_requests == {("r-1", "id-1"): req}
def test_with_reqest_ids(conn): populate_spot_requests_cache("region-a", request_ids=[1, 2]) conn.assert_has_calls( [mock.call().get_all_spot_instance_requests(request_ids=[1, 2])])
def test_no_reqest_ids(conn): populate_spot_requests_cache("region-a") conn.assert_has_calls( [mock.call().get_all_spot_instance_requests()])
def test_no_reqest_ids(conn): populate_spot_requests_cache("region-a") conn.assert_has_calls([mock.call().get_all_spot_instance_requests()])