Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(602)

Side by Side Diff: juju/providers/ec2/tests/common.py

Issue 6850044: providers/ec2: support VPC
Patch Set: providers/ec2: support VPC Created 12 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 from twisted.internet.defer import fail, succeed, inlineCallbacks, returnValue 2 from twisted.internet.defer import fail, succeed, inlineCallbacks, returnValue
3 3
4 from txaws.s3.client import S3Client 4 from txaws.s3.client import S3Client
5 from txaws.s3.exception import S3Error 5 from txaws.s3.exception import S3Error
6 from txaws.ec2.client import EC2Client 6 from txaws.ec2.client import EC2Client
7 from txaws.ec2.exception import EC2Error 7 from txaws.ec2.exception import EC2Error
8 from txaws.ec2.model import Instance, Reservation, SecurityGroup 8 from txaws.ec2.model import Instance, Reservation, SecurityGroup
9 9
10 from juju.lib import serializer 10 from juju.lib import serializer
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 get_public_key(MATCH(match_config)) 101 get_public_key(MATCH(match_config))
102 self.mocker.result("zebra") 102 self.mocker.result("zebra")
103 103
104 get_ami_args = get_ami_args or ( 104 get_ami_args = get_ami_args or (
105 "splendid", "amd64", "us-east-1", False, False) 105 "splendid", "amd64", "us-east-1", False, False)
106 get_ami = self.mocker.replace( 106 get_ami = self.mocker.replace(
107 "juju.providers.ec2.utils.get_current_ami") 107 "juju.providers.ec2.utils.get_current_ami")
108 get_ami(*get_ami_args) 108 get_ami(*get_ami_args)
109 self.mocker.result(succeed(ami_name)) 109 self.mocker.result(succeed(ami_name))
110 110
111 def _mock_create_group(self): 111 def _mock_create_group(self, vpc_id=None):
112 group_name = "juju-%s" % self.env_name 112 group_name = "juju-%s" % self.env_name
113 self.ec2.create_security_group( 113 self.ec2.create_security_group(
114 group_name, "juju group for %s" % self.env_name) 114 group_name, "juju group for %s" % self.env_name,
115 self.mocker.result(succeed(True)) 115 vpc_id=vpc_id)
116 self.mocker.result(succeed("sg-a1a1a1a1"))
116 117
117 self.ec2.authorize_security_group( 118 self.ec2.authorize_security_group(
118 group_name, ip_protocol="tcp", from_port="22", 119 group_id="sg-a1a1a1a1", ip_protocol="tcp", from_port="22",
119 to_port="22", cidr_ip="0.0.0.0/0") 120 to_port="22", cidr_ip="0.0.0.0/0")
120 self.mocker.result(succeed([self.env_name])) 121 self.mocker.result(succeed([self.env_name]))
121 122
122 self.ec2.describe_security_groups(group_name) 123 self.ec2.describe_security_groups(group_name)
123 self.mocker.result(succeed( 124 self.mocker.result(succeed(
124 [SecurityGroup(group_name, "", owner_id="123")])) 125 [SecurityGroup("sg-a1a1a1a1", group_name, "", owner_id="123")]))
125 126
126 self.ec2.authorize_security_group( 127 self.ec2.authorize_security_group(
127 group_name, source_group_name=group_name, 128 group_id="sg-a1a1a1a1", source_group_name=group_name,
128 source_group_owner_id="123") 129 source_group_owner_id="123")
129 self.mocker.result(succeed(True)) 130 self.mocker.result(succeed(True))
130 131
131 def _mock_create_machine_group(self, machine_id): 132 def _mock_create_machine_group(self, machine_id, vpc_id=None):
132 machine_group_name = "juju-%s-%s" % (self.env_name, machine_id) 133 machine_group_name = "juju-%s-%s" % (self.env_name, machine_id)
133 self.ec2.create_security_group( 134 self.ec2.create_security_group(
134 machine_group_name, "juju group for %s machine %s" % ( 135 machine_group_name, "juju group for %s machine %s" % (
135 self.env_name, machine_id)) 136 self.env_name, machine_id), vpc_id=vpc_id)
136 self.mocker.result(succeed(True)) 137 self.mocker.result(succeed("sg-b2b2b2b2"))
137 138
138 def _mock_get_zookeeper_hosts(self, hosts=None): 139 def _mock_get_zookeeper_hosts(self, hosts=None):
139 """ 140 """
140 Try to encapsulate a variety of behaviors here.. 141 Try to encapsulate a variety of behaviors here..
141 142
142 if hosts is None, a default host is used. 143 if hosts is None, a default host is used.
143 if hosts is False, no s3 state is returned 144 if hosts is False, no s3 state is returned
144 if hosts are passed as a list of instances, they 145 if hosts are passed as a list of instances, they
145 are returned. 146 are returned.
146 """ 147 """
147 148
148 if hosts is None: 149 if hosts is None:
149 hosts = [self.get_instance( 150 hosts = [self.get_instance(
150 "i-es-zoo", private_dns_name="es.example.internal")] 151 "i-es-zoo", private_dns_name="es.example.internal", private_ip_a ddress="1.1.1.1")]
151 152
152 self.s3.get_object(self.env_name, "provider-state") 153 self.s3.get_object(self.env_name, "provider-state")
153 if hosts is False: 154 if hosts is False:
154 error = S3Error("<error/>", 404) 155 error = S3Error("<error/>", 404)
155 error.errors = [{"Code": "NoSuchKey"}] 156 error.errors = [{"Code": "NoSuchKey"}]
156 self.mocker.result(fail(error)) 157 self.mocker.result(fail(error))
157 return 158 return
158 159
159 state = serializer.dump({ 160 state = serializer.dump({
160 "zookeeper-instances": 161 "zookeeper-instances":
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 201
201 class Observed(object): 202 class Observed(object):
202 """Minimal wrapper just to ensure :method:`add` returns a `Deferred`.""" 203 """Minimal wrapper just to ensure :method:`add` returns a `Deferred`."""
203 204
204 def __init__(self): 205 def __init__(self):
205 self.items = set() 206 self.items = set()
206 207
207 def add(self, item): 208 def add(self, item):
208 self.items.add(item) 209 self.items.add(item)
209 return succeed(True) 210 return succeed(True)
OLDNEW
« no previous file with comments | « juju/providers/ec2/securitygroup.py ('k') | juju/providers/ec2/tests/data/launch_cloud_init_ip_address » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b