def test_get_all_pricing_one_instance(self): price_df = aws_pricing.get_instance_pricing(['t3.large']) self.assertIsInstance(price_df, pd.DataFrame) columns = list(price_df.columns) expected_columns = [ 'instance_type', 'region', 'spot_price', 'on_demand_price' ] self.assertEquals(columns, expected_columns)
def test_spot_less_than_on_demand(self): instance_type_list = ['c5.18xlarge', 'm5a.large', 'c5.xlarge'] price_df = aws_pricing.get_instance_pricing(instance_type_list) spot_prices = price_df[aws_pricing.DF_COL_SPOT_PRICE] on_demand_prices = price_df[aws_pricing.DF_COL_ON_DEMAND_PRICE] compare_results = spot_prices <= on_demand_prices self.assertTrue(np.all(compare_results))
def test_get_all_pricing_multiple_instance(self): instance_type_list = ['c5.18xlarge', 'm5a.large', 'c5.xlarge'] price_df = aws_pricing.get_instance_pricing(instance_type_list) self.assertIsInstance(price_df, pd.DataFrame) columns = list(price_df.columns) expected_columns = [ 'instance_type', 'region', 'spot_price', 'on_demand_price' ] instance_types_df = price_df[aws_pricing.DF_COL_INSTANCE_TYPE].unique() self.assertEquals(columns, expected_columns) self.assertCountEqual(instance_type_list, instance_types_df)
def add_estimated_price(df): """ This function adds the spot and on-demand pricing to the dataframe """ instance_types = df["instance_type"].tolist() price = ap.get_instance_pricing(instance_types) complete_df = pd.merge(df, price, on="instance_type") complete_df["est_cost_spot_price"] = \ complete_df["estimated_time_aws"]*complete_df["spot_price"]/3600 complete_df["est_cost_on_demand_price"] = \ complete_df["estimated_time_aws"]*complete_df["on_demand_price"]/3600 return complete_df
def test_get_all_pricing_multiple_instance(self): instance_type_list = ['c5.18xlarge', 'm5a.large', 'c5.xlarge'] price_df = aws_pricing.get_instance_pricing(instance_type_list) self.assertIsInstance(price_df, pd.DataFrame) columns = list(price_df.columns) expected_columns = [ aws_pricing.DF_COL_INSTANCE_TYPE, aws_pricing.DF_COL_REGION, aws_pricing.DF_COL_SPOT_PRICE, aws_pricing.DF_COL_ON_DEMAND_PRICE ] instance_types_df = price_df[aws_pricing.DF_COL_INSTANCE_TYPE].unique() self.assertEquals(columns, expected_columns) self.assertCountEqual(instance_type_list, instance_types_df)
def test_add_estimated_price(self): """ This function tests adding the spot and on-demand pricing to the dataframe """ benchmark_df = rc.get_benchmark_data() times, percents = [2, 4, 6], [1, 5, 10] est_time_user = tt.find_total_time(times, percents) user_benchmark = br.run_benchmark() est_time_aws = benchmark_df[['runtime']] \ / user_benchmark * est_time_user[0] benchmark_df["estimated_time_aws"] = est_time_aws instance_types = benchmark_df["instance_type"].tolist() price = ap.get_instance_pricing(instance_types) complete_df = pd.merge(benchmark_df, price, on="instance_type") complete_df["est_cost_spot_price"] = \ complete_df["estimated_time_aws"] \ * complete_df["spot_price"] / 3600 complete_df["est_cost_on_demand_price"] = \ complete_df["estimated_time_aws"] \ * complete_df["on_demand_price"] / 3600 self.assertGreater(complete_df.shape[0], 0)