def test_ba_get_bid(self): """ Tests that the bid_advisor's get_new_bid() method returns correct bid information. """ bidadv = AWSBidAdvisor(REFRESH_INTERVAL, REFRESH_INTERVAL, REGION) instance_type = "m3.large" zones = ["us-west-2b"] # Manually populate the prices so that spot-instance prices are chosen. bidadv.on_demand_price_dict["m3.large"] = "100" bidadv.spot_price_list = [{ 'InstanceType': instance_type, 'SpotPrice': '80', 'AvailabilityZone': "us-west-2b" }] bid_info = bidadv.get_new_bid(zones, instance_type) assert bid_info is not None, "BidAdvisor didn't return any " + \ "now bid information." assert bid_info["type"] == "spot" assert isinstance(bid_info["price"], str) # Manually populate the prices so that on-demand instances are chosen. bidadv.spot_price_list = [{ 'InstanceType': instance_type, 'SpotPrice': '85', 'AvailabilityZone': "us-west-2b" }] bid_info = bidadv.get_new_bid(zones, instance_type) assert bid_info is not None, "BidAdvisor didn't return any now " + \ "bid information." assert bid_info["type"] == "on-demand"
def test_ba_price_update(self): """ Tests that the AXBidVisor actually updates the pricing info. """ bidadv = AWSBidAdvisor(REFRESH_INTERVAL, REFRESH_INTERVAL, REGION) od_updater = bidadv.OnDemandUpdater(bidadv) od_updater.get_on_demand_pricing() sp_updater = bidadv.SpotInstancePriceUpdater(bidadv) sp_updater.get_spot_price_info() # Verify that the pricing info was populated. assert len(bidadv.on_demand_price_dict) > 0 assert len(bidadv.spot_price_list) > 0 # Make the price dicts empty to check if they get updated. bidadv.on_demand_price_dict = {} bidadv.spot_price_list = {} od_updater.get_on_demand_pricing() sp_updater.get_spot_price_info() # Verify that the pricing info is populated again. assert len(bidadv.on_demand_price_dict) > 0 assert len(bidadv.spot_price_list) > 0