171
171
self.assertEquals(reservation.owner_id, "123456789012")
173
173
group = reservation.groups[0]
174
self.assertEquals(group[0], "sg-64f9eb08")
175
self.assertEquals(group[1], "default")
174
self.assertEquals(group, "default")
177
176
self.assertEquals(instance.instance_id, "i-abcdef01")
178
177
self.assertEquals(instance.instance_state, "running")
202
201
self.assertEquals(reservation.owner_id, "123456789012")
204
203
group = reservation.groups[0]
205
self.assertEquals(group[0], "sg-64f9eb08")
206
self.assertEquals(group[1], "default")
204
self.assertEquals(group, "default")
208
206
self.assertEquals(instance.instance_id, "i-abcdef01")
209
207
self.assertEquals(instance.instance_state, "running")
333
331
self.assertEquals(reservation.owner_id, "495219933132")
335
333
group = reservation.groups[0]
336
self.assertEquals(group[0], "sg-64f9eb08")
337
self.assertEquals(group[1], "default")
334
self.assertEquals(group, "default")
339
336
self.assertEquals(instance.instance_id, "i-2ba64342")
340
337
self.assertEquals(instance.instance_state, "pending")
380
377
ramdisk_id=u"r-1234")
381
378
d.addCallback(self.check_parsed_run_instances)
383
def test_run_instances_with_subnet(self):
384
class StubQuery(object):
385
def __init__(stub, action="", creds=None, endpoint=None,
387
self.assertEqual(action, "RunInstances")
388
self.assertEqual(creds.access_key, "foo")
389
self.assertEqual(creds.secret_key, "bar")
392
{"ImageId": "ami-1234", "MaxCount": "2", "MinCount": "1",
393
"SecurityGroupId.1": u"sg-a72d9f92e", "KeyName": u"default",
394
"UserData": "Zm9v", "InstanceType": u"m1.small",
395
"Placement.AvailabilityZone": u"us-east-1b",
396
"KernelId": u"k-1234", "RamdiskId": u"r-1234",
397
"SubnetId": "subnet-a72d829f"})
401
payload.sample_run_instances_result)
403
creds = AWSCredentials("foo", "bar")
404
ec2 = client.EC2Client(creds, query_factory=StubQuery)
405
d = ec2.run_instances("ami-1234", 1, 2, security_group_ids=[u"sg-a72d9f92e"],
406
key_name=u"default", user_data=u"foo", instance_type=u"m1.small",
407
availability_zone=u"us-east-1b", kernel_id=u"k-1234",
408
ramdisk_id=u"r-1234", subnet_id="subnet-a72d829f")
409
d.addCallback(self.check_parsed_run_instances)
411
def test_run_instances_with_subnet_but_without_secgroup_id(self):
412
creds = AWSCredentials("foo", "bar")
413
ec2 = client.EC2Client(creds)
414
error = self.assertRaises(ValueError, ec2.run_instances, "ami-1234", 1, 2,
415
key_name=u"default", user_data=u"foo", instance_type=u"m1.small",
416
availability_zone=u"us-east-1b", kernel_id=u"k-1234",
417
ramdisk_id=u"r-1234", subnet_id="subnet-a72d829f")
420
"You must specify the security_group_ids with the subnet_id"
423
def test_run_instances_without_subnet_and_secgroups(self):
424
creds = AWSCredentials("foo", "bar")
425
ec2 = client.EC2Client(creds)
426
error = self.assertRaises(ValueError, ec2.run_instances, "ami-1234", 1, 2,
427
key_name=u"default", user_data=u"foo", instance_type=u"m1.small",
428
availability_zone=u"us-east-1b", kernel_id=u"k-1234",
429
ramdisk_id=u"r-1234")
432
("You must specify either the subnet_id and "
433
"security_group_ids or security_groups")
437
381
class EC2ClientSecurityGroupsTestCase(TXAWSTestCase):
497
440
security_group = security_groups[0]
498
441
self.assertEquals(security_group.owner_id,
499
442
"UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM")
500
self.assertEquals(security_group.id, "sg-a1a1a1")
501
443
self.assertEquals(security_group.name, "MessageServers")
502
444
self.assertEquals(security_group.description, "Message Servers")
503
445
self.assertEquals(security_group.allowed_groups, [])
509
451
security_group = security_groups[1]
510
452
self.assertEquals(security_group.owner_id,
511
453
"UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM")
512
self.assertEquals(security_group.id, "sg-c3c3c3")
513
454
self.assertEquals(security_group.name, "WebServers")
514
455
self.assertEquals(security_group.description, "Web Servers")
515
456
self.assertEquals([(pair.user_id, pair.group_name)
642
583
def submit(self):
643
584
return succeed(payload.sample_create_security_group)
645
def check_result(id):
646
self.assertEquals(id, "sg-1a2b3c4d")
648
586
creds = AWSCredentials("foo", "bar")
649
587
ec2 = client.EC2Client(creds, query_factory=StubQuery)
650
588
d = ec2.create_security_group(
652
590
"The group for the web server farm.")
653
return d.addCallback(check_result)
655
def test_create_security_group_with_VPC(self):
656
class StubQuery(object):
658
def __init__(stub, action="", creds=None, endpoint=None,
660
self.assertEqual(action, "CreateSecurityGroup")
661
self.assertEqual(creds.access_key, "foo")
662
self.assertEqual(creds.secret_key, "bar")
663
self.assertEqual(other_params, {
664
"GroupName": "WebServers",
665
"GroupDescription": "The group for the web server farm.",
670
return succeed(payload.sample_create_security_group)
672
def check_result(id):
673
self.assertEquals(id, "sg-1a2b3c4d")
675
creds = AWSCredentials("foo", "bar")
676
ec2 = client.EC2Client(creds, query_factory=StubQuery)
677
d = ec2.create_security_group(
679
"The group for the web server farm.",
681
return d.addCallback(check_result)
683
def test_delete_security_group_using_name(self):
591
return self.assertTrue(d)
593
def test_delete_security_group(self):
685
595
L{EC2Client.delete_security_group} returns a C{Deferred} that
686
596
eventually fires with a true value, indicating the success of the
705
615
d = ec2.delete_security_group("WebServers")
706
616
return self.assertTrue(d)
708
def test_delete_security_group_using_id(self):
710
L{EC2Client.delete_security_group} returns a C{Deferred} that
711
eventually fires with a true value, indicating the success of the
714
class StubQuery(object):
716
def __init__(stub, action="", creds=None, endpoint=None,
718
self.assertEqual(action, "DeleteSecurityGroup")
719
self.assertEqual(creds.access_key, "foo")
720
self.assertEqual(creds.secret_key, "bar")
721
self.assertEqual(other_params, {
722
"GroupId": "sg-a1a1a1",
726
return succeed(payload.sample_delete_security_group)
728
creds = AWSCredentials("foo", "bar")
729
ec2 = client.EC2Client(creds, query_factory=StubQuery)
730
d = ec2.delete_security_group(id="sg-a1a1a1")
731
return self.assertTrue(d)
733
def test_delete_security_group_without_id_and_name(self):
734
creds = AWSCredentials("foo", "bar")
735
ec2 = client.EC2Client(creds)
736
error = self.assertRaises(ValueError, ec2.delete_security_group)
739
"You must provide either the security group name or id",
742
618
def test_delete_security_group_failure(self):
744
620
L{EC2Client.delete_security_group} returns a C{Deferred} that
800
676
creds = AWSCredentials("foo", "bar")
801
677
ec2 = client.EC2Client(creds, query_factory=StubQuery)
802
678
d = ec2.authorize_security_group(
803
group_name="WebServers", source_group_name="AppServers",
804
source_group_owner_id="123456789123")
805
return self.assertTrue(d)
807
def test_authorize_security_group_using_group_id(self):
808
class StubQuery(object):
810
def __init__(stub, action="", creds=None, endpoint=None,
812
self.assertEqual(action, "AuthorizeSecurityGroupIngress")
813
self.assertEqual(creds.access_key, "foo")
814
self.assertEqual(creds.secret_key, "bar")
815
self.assertEqual(other_params, {
816
"GroupId": "sg-a1b2c3d4e5f6",
817
"SourceSecurityGroupName": "AppServers",
818
"SourceSecurityGroupOwnerId": "123456789123",
822
return succeed(payload.sample_authorize_security_group)
824
creds = AWSCredentials("foo", "bar")
825
ec2 = client.EC2Client(creds, query_factory=StubQuery)
826
d = ec2.authorize_security_group(
827
group_id="sg-a1b2c3d4e5f6", source_group_name="AppServers",
828
source_group_owner_id="123456789123")
829
return self.assertTrue(d)
831
def test_authorize_security_group_without_group_id_and_group_name(self):
832
creds = AWSCredentials("foo", "bar")
833
ec2 = client.EC2Client(creds)
834
error = self.assertRaises(ValueError, ec2.authorize_security_group,
835
source_group_name="AppServers", source_group_owner_id="123456789123")
838
"You must specify either the group name of the group id.")
679
"WebServers", source_group_name="AppServers",
680
source_group_owner_id="123456789123")
681
return self.assertTrue(d)
840
683
def test_authorize_security_group_with_ip_permissions(self):
864
707
creds = AWSCredentials("foo", "bar")
865
708
ec2 = client.EC2Client(creds, query_factory=StubQuery)
866
709
d = ec2.authorize_security_group(
867
group_name="WebServers", ip_protocol="tcp", from_port="22", to_port="80",
710
"WebServers", ip_protocol="tcp", from_port="22", to_port="80",
868
711
cidr_ip="0.0.0.0/0")
869
712
return self.assertTrue(d)
880
723
creds = AWSCredentials("foo", "bar")
881
724
ec2 = client.EC2Client(creds)
882
error = self.assertRaises(ValueError, ec2.authorize_security_group,
883
group_name="WebServers", ip_protocol="tcp", from_port="22")
886
("You must specify either both group parameters or all the "
725
self.assertRaises(ValueError, ec2.authorize_security_group,
726
"WebServers", ip_protocol="tcp", from_port="22")
728
ec2.authorize_security_group(
729
"WebServers", ip_protocol="tcp", from_port="22")
730
except Exception, error:
733
("You must specify either both group parameters or all the "
889
736
def test_authorize_group_permission(self):
975
822
source_group_owner_id="123456789123")
976
823
return self.assertTrue(d)
978
def test_revoke_security_group_using_group_id(self):
979
class StubQuery(object):
981
def __init__(stub, action="", creds=None, endpoint=None,
983
self.assertEqual(action, "RevokeSecurityGroupIngress")
984
self.assertEqual(creds.access_key, "foo")
985
self.assertEqual(creds.secret_key, "bar")
986
self.assertEqual(other_params, {
987
"GroupId": "sg-a1a1a1",
988
"SourceSecurityGroupName": "AppServers",
989
"SourceSecurityGroupOwnerId": "123456789123",
993
return succeed(payload.sample_revoke_security_group)
995
creds = AWSCredentials("foo", "bar")
996
ec2 = client.EC2Client(creds, query_factory=StubQuery)
997
d = ec2.revoke_security_group(
998
group_id="sg-a1a1a1", source_group_name="AppServers",
999
source_group_owner_id="123456789123")
1000
return self.assertTrue(d)
1002
825
def test_revoke_security_group_with_ip_permissions(self):
1004
827
L{EC2Client.revoke_security_group} returns a C{Deferred} that
1030
853
cidr_ip="0.0.0.0/0")
1031
854
return self.assertTrue(d)
1033
def test_revoke_security_group_without_group_id_and_group_name(self):
1034
creds = AWSCredentials("foo", "bar")
1035
ec2 = client.EC2Client(creds)
1036
error = self.assertRaises(ValueError, ec2.revoke_security_group,
1037
source_group_name="AppServers", source_group_owner_id="123456789123")
1040
"You must specify either the group name of the group id.")
1042
856
def test_revoke_security_group_with_missing_parameters(self):
1044
858
L{EC2Client.revoke_security_group} returns a C{Deferred} that
1051
865
creds = AWSCredentials("foo", "bar")
1052
866
ec2 = client.EC2Client(creds)
1053
error = self.assertRaises(ValueError, ec2.revoke_security_group,
1054
group_name="WebServers", ip_protocol="tcp", from_port="22")
1057
("You must specify either both group parameters or all the "
867
self.assertRaises(ValueError, ec2.authorize_security_group,
868
"WebServers", ip_protocol="tcp", from_port="22")
870
ec2.authorize_security_group(
871
"WebServers", ip_protocol="tcp", from_port="22")
872
except Exception, error:
875
("You must specify either both group parameters or all the "
1060
878
def test_revoke_group_permission(self):