Search in sources :

Example 66 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestTagValueExclusionRule method testExcludeTaggedResourceWithTagAndValueMatch1.

@Test
public void testExcludeTaggedResourceWithTagAndValueMatch1() {
    Resource r1 = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withOwnerEmail("owner@foo.com");
    r1.setTag("tag", null);
    r1.setTag("tag1", "excludeme");
    r1.setTag("tag2", "somethingelse");
    TagValueExclusionRule rule = new TagValueExclusionRule(exclusionTags);
    Assert.assertTrue(rule.isValid(r1));
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 67 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestTagValueExclusionRule method testExcludeTaggedResourceValueMatchOnly.

@Test
public void testExcludeTaggedResourceValueMatchOnly() {
    Resource r1 = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withOwnerEmail("owner@foo.com");
    r1.setTag("tag", null);
    r1.setTag("tagA", "excludeme");
    r1.setTag("tagB", "excludeme2");
    TagValueExclusionRule rule = new TagValueExclusionRule(exclusionTags);
    Assert.assertFalse(rule.isValid(r1));
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 68 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestTagValueExclusionRule method testNameValueConstructor.

@Test
public void testNameValueConstructor() {
    Resource r1 = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withOwnerEmail("owner@foo.com");
    r1.setTag("tag1", "excludeme");
    String names = "tag1";
    String vals = "excludeme";
    TagValueExclusionRule rule = new TagValueExclusionRule(names.split(","), vals.split(","));
    Assert.assertTrue(rule.isValid(r1));
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 69 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestTagValueExclusionRule method testExcludeTaggedResourceWithTagAndValueMatchBoth.

@Test
public void testExcludeTaggedResourceWithTagAndValueMatchBoth() {
    Resource r1 = new AWSResource().withId("i-12345678901234567").withResourceType(AWSResourceType.INSTANCE).withOwnerEmail("owner@foo.com");
    r1.setTag("tag", null);
    r1.setTag("tag1", "excludeme");
    r1.setTag("tag2", "excludeme2");
    TagValueExclusionRule rule = new TagValueExclusionRule(exclusionTags);
    Assert.assertTrue(rule.isValid(r1));
}
Also used : AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 70 with Resource

use of com.netflix.simianarmy.Resource in project SimianArmy by Netflix.

the class TestUntaggedRule method testUntaggedResource.

@Test
public void testUntaggedResource() {
    DateTime now = DateTime.now();
    Resource imageResource = new AWSResource().withId("ami-123123").withResourceType(AWSResourceType.IMAGE);
    Resource asgResource = new AWSResource().withId("my-cool-asg").withResourceType(AWSResourceType.ASG);
    Resource ebsSnapshotResource = new AWSResource().withId("snap-12345678901234567").withResourceType(AWSResourceType.EBS_SNAPSHOT);
    Resource lauchConfigurationResource = new AWSResource().withId("my-cool-launch-configuration").withResourceType(AWSResourceType.LAUNCH_CONFIG);
    Set<String> tags = new HashSet<String>();
    tags.add("tag1");
    tags.add("tag2");
    int retentionDaysWithOwner = 4;
    int retentionDaysWithoutOwner = 8;
    UntaggedRule rule = new UntaggedRule(new TestMonkeyCalendar(), tags, retentionDaysWithOwner, retentionDaysWithoutOwner);
    Assert.assertFalse(rule.isValid(imageResource));
    Assert.assertFalse(rule.isValid(asgResource));
    Assert.assertFalse(rule.isValid(ebsSnapshotResource));
    Assert.assertFalse(rule.isValid(lauchConfigurationResource));
    TestUtils.verifyTerminationTimeRough(imageResource, retentionDaysWithoutOwner, now);
    TestUtils.verifyTerminationTimeRough(asgResource, retentionDaysWithoutOwner, now);
    TestUtils.verifyTerminationTimeRough(ebsSnapshotResource, retentionDaysWithoutOwner, now);
    TestUtils.verifyTerminationTimeRough(lauchConfigurationResource, retentionDaysWithoutOwner, now);
}
Also used : TestMonkeyCalendar(com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar) AWSResource(com.netflix.simianarmy.aws.AWSResource) AWSResource(com.netflix.simianarmy.aws.AWSResource) Resource(com.netflix.simianarmy.Resource) DateTime(org.joda.time.DateTime) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Resource (com.netflix.simianarmy.Resource)145 AWSResource (com.netflix.simianarmy.aws.AWSResource)132 Test (org.testng.annotations.Test)110 TestMonkeyCalendar (com.netflix.simianarmy.aws.janitor.rule.TestMonkeyCalendar)64 DateTime (org.joda.time.DateTime)60 Date (java.util.Date)45 MonkeyCalendar (com.netflix.simianarmy.MonkeyCalendar)21 AWSClient (com.netflix.simianarmy.client.aws.AWSClient)18 JsonNode (org.codehaus.jackson.JsonNode)17 AWSResourceType (com.netflix.simianarmy.aws.AWSResourceType)11 BeforeTest (org.testng.annotations.BeforeTest)9 AutoScalingGroup (com.amazonaws.services.autoscaling.model.AutoScalingGroup)8 LoadBalancerDescription (com.amazonaws.services.elasticloadbalancing.model.LoadBalancerDescription)6 HashSet (java.util.HashSet)6 AutoScalingInstanceDetails (com.amazonaws.services.autoscaling.model.AutoScalingInstanceDetails)5 Instance (com.amazonaws.services.ec2.model.Instance)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 RowMapper (org.springframework.jdbc.core.RowMapper)5 Snapshot (com.amazonaws.services.ec2.model.Snapshot)4