def test_provision_hostclass_sched_some_none(self, mock_config, **kwargs): """ Provision creates the proper autoscaling group sizes with scheduled sizes """ aws = DiscoAWS(config=mock_config, environment_name=TEST_ENV_NAME) aws.log_metrics = MagicMock() aws.update_elb = MagicMock(return_value=None) with patch("disco_aws_automation.DiscoAWS.get_meta_network", return_value=_get_meta_network_mock()): with patch("boto.ec2.connection.EC2Connection.get_all_snapshots", return_value=[]): with patch( "disco_aws_automation.DiscoAWS.create_scaling_schedule", return_value=None): with patch( "boto.ec2.autoscale.AutoScaleConnection.create_or_update_tags", return_value=None): aws.provision(ami=self._get_image_mock(aws), hostclass="mhcunittest", owner="unittestuser", min_size="", desired_size="2@1 0 * * *:3@6 0 * * *", max_size="") _ag = aws.autoscale.get_groups()[0] print("({0}, {1}, {2})".format(_ag.min_size, _ag.desired_capacity, _ag.max_size)) self.assertEqual(_ag.min_size, 0) # minimum of listed sizes self.assertEqual(_ag.desired_capacity, 3) # maximum of listed sizes self.assertEqual(_ag.max_size, 3) # maximum of listed sizes
def test_provision_hc_with_chaos_using_config(self, mock_config, **kwargs): """ Provision creates the proper launch configuration and autoscaling group with chaos from config """ config_dict = get_default_config_dict() config_dict["mhcunittest"]["chaos"] = "True" aws = DiscoAWS(config=get_mock_config(config_dict), environment_name=TEST_ENV_NAME) mock_ami = self._get_image_mock(aws) aws.log_metrics = MagicMock() aws.update_elb = MagicMock(return_value=None) with patch("disco_aws_automation.DiscoAWS.get_meta_network", return_value=_get_meta_network_mock()): with patch("boto.ec2.connection.EC2Connection.get_all_snapshots", return_value=[]): with patch("disco_aws_automation.DiscoAWS.create_scaling_schedule", return_value=None): with patch("boto.ec2.autoscale.AutoScaleConnection.create_or_update_tags", return_value=None): metadata = aws.provision(ami=mock_ami, hostclass="mhcunittest", owner="unittestuser", min_size=1, desired_size=1, max_size=1) self.assertEqual(metadata["hostclass"], "mhcunittest") self.assertFalse(metadata["no_destroy"]) self.assertTrue(metadata["chaos"]) _lc = aws.autoscale.get_configs()[0] self.assertRegexpMatches(_lc.name, r".*_mhcunittest_[0-9]*") self.assertEqual(_lc.image_id, mock_ami.id) self.assertTrue(aws.autoscale.has_group("mhcunittest")) _ag = aws.autoscale.get_groups()[0] self.assertEqual(_ag.name, "unittestenv_mhcunittest") self.assertEqual(_ag.min_size, 1) self.assertEqual(_ag.max_size, 1) self.assertEqual(_ag.desired_capacity, 1)
def test_provision_hostclass_sched_all_none(self, mock_config, **kwargs): """ Provision creates the proper autoscaling group sizes with scheduled sizes """ aws = DiscoAWS(config=mock_config, environment_name=TEST_ENV_NAME) aws.log_metrics = MagicMock() aws.update_elb = MagicMock(return_value=None) with patch("disco_aws_automation.DiscoAWS.get_meta_network", return_value=_get_meta_network_mock()): with patch("boto.ec2.connection.EC2Connection.get_all_snapshots", return_value=[]): with patch("disco_aws_automation.DiscoAWS.create_scaling_schedule", return_value=None): with patch("boto.ec2.autoscale.AutoScaleConnection.create_or_update_tags", return_value=None): aws.provision(ami=self._get_image_mock(aws), hostclass="mhcunittest", owner="unittestuser", min_size="", desired_size="", max_size="") _ag0 = aws.autoscale.get_groups()[0] self.assertEqual(_ag0.min_size, 0) # minimum of listed sizes self.assertEqual(_ag0.desired_capacity, 0) # maximum of listed sizes self.assertEqual(_ag0.max_size, 0) # maximum of listed sizes with patch("disco_aws_automation.DiscoAWS.get_meta_network", return_value=_get_meta_network_mock()): with patch("boto.ec2.connection.EC2Connection.get_all_snapshots", return_value=[]): with patch("disco_aws_automation.DiscoAWS.create_scaling_schedule", return_value=None): with patch("boto.ec2.autoscale.AutoScaleConnection.create_or_update_tags", return_value=None): aws.provision(ami=self._get_image_mock(aws), hostclass="mhcunittest", owner="unittestuser", min_size="3", desired_size="6", max_size="9") _ag1 = aws.autoscale.get_groups()[0] self.assertEqual(_ag1.min_size, 3) # minimum of listed sizes self.assertEqual(_ag1.desired_capacity, 6) # maximum of listed sizes self.assertEqual(_ag1.max_size, 9) # maximum of listed sizes with patch("disco_aws_automation.DiscoAWS.get_meta_network", return_value=_get_meta_network_mock()): with patch("boto.ec2.connection.EC2Connection.get_all_snapshots", return_value=[]): with patch("disco_aws_automation.DiscoAWS.create_scaling_schedule", return_value=None): with patch("boto.ec2.autoscale.AutoScaleConnection.create_or_update_tags", return_value=None): aws.provision(ami=self._get_image_mock(aws), hostclass="mhcunittest", owner="unittestuser", min_size="", desired_size="", max_size="") _ag2 = aws.autoscale.get_groups()[0] self.assertEqual(_ag2.min_size, 3) # minimum of listed sizes self.assertEqual(_ag2.desired_capacity, 6) # maximum of listed sizes self.assertEqual(_ag2.max_size, 9) # maximum of listed sizes
def test_provision_hc_with_chaos_using_config(self, mock_config, **kwargs): """ Provision creates the proper launch configuration and autoscaling group with chaos from config """ config_dict = get_default_config_dict() config_dict["mhcunittest"]["chaos"] = "True" aws = DiscoAWS(config=get_mock_config(config_dict), environment_name=TEST_ENV_NAME) mock_ami = self._get_image_mock(aws) aws.log_metrics = MagicMock() aws.update_elb = MagicMock(return_value=None) with patch("disco_aws_automation.DiscoAWS.get_meta_network", return_value=_get_meta_network_mock()): with patch("boto.ec2.connection.EC2Connection.get_all_snapshots", return_value=[]): with patch( "disco_aws_automation.DiscoAWS.create_scaling_schedule", return_value=None): with patch( "boto.ec2.autoscale.AutoScaleConnection.create_or_update_tags", return_value=None): metadata = aws.provision(ami=mock_ami, hostclass="mhcunittest", owner="unittestuser", min_size=1, desired_size=1, max_size=1) self.assertEqual(metadata["hostclass"], "mhcunittest") self.assertFalse(metadata["no_destroy"]) self.assertTrue(metadata["chaos"]) _lc = aws.autoscale.get_configs()[0] self.assertRegexpMatches(_lc.name, r".*_mhcunittest_[0-9]*") self.assertEqual(_lc.image_id, mock_ami.id) self.assertTrue(aws.autoscale.has_group("mhcunittest")) _ag = aws.autoscale.get_groups()[0] self.assertEqual(_ag.name, "unittestenv_mhcunittest") self.assertEqual(_ag.min_size, 1) self.assertEqual(_ag.max_size, 1) self.assertEqual(_ag.desired_capacity, 1)