110110 'publicurl' : endpoint_publicurl ,
111111 'service_id' : endpoint_service_id ,
112112}
113+ SERVICE_NAME = 'service-name-' + uuid .uuid4 ().hex
114+ SERVICE_ID = 'service-id-' + uuid .uuid4 ().hex
113115
114116
115117def fake_auth_ref (fake_token , fake_service = None ):
@@ -123,12 +125,12 @@ def fake_auth_ref(fake_token, fake_service=None):
123125 # Create a service catalog
124126 if fake_service :
125127 service = token .add_service (
126- fake_service [ ' type' ] ,
127- fake_service [ ' name' ] ,
128+ fake_service . type ,
129+ fake_service . name ,
128130 )
129131 # TODO(dtroyer): Add an 'id' element to KSA's _Service fixure
130- service ['id' ] = fake_service [ 'id' ]
131- for e in fake_service [ ' endpoints' ] :
132+ service ['id' ] = fake_service . id
133+ for e in fake_service . endpoints :
132134 # KSA's _Service fixture copies publicURL to internalURL and
133135 # adminURL if they do not exist. Soooo helpful...
134136 internal = e .get ('internalURL' , None )
@@ -224,3 +226,241 @@ def create_one_extension(attrs=None):
224226 info = copy .deepcopy (extension_info ),
225227 loaded = True )
226228 return extension
229+
230+
231+ class FakeCatalog (object ):
232+ """Fake one or more catalog."""
233+
234+ @staticmethod
235+ def create_catalog (attrs = None ):
236+ """Create a fake catalog.
237+
238+ :param Dictionary attrs:
239+ A dictionary with all attributes
240+ :return:
241+ A FakeResource object with id, name, type and so on.
242+ """
243+ attrs = attrs or {}
244+
245+ # Set default attributes.
246+ catalog_info = {
247+ 'id' : SERVICE_ID ,
248+ 'type' : 'compute' ,
249+ 'name' : 'supernova' ,
250+ 'endpoints' : [
251+ {
252+ 'region' : 'one' ,
253+ 'publicURL' : 'https://public.one.example.com' ,
254+ 'internalURL' : 'https://internal.one.example.com' ,
255+ 'adminURL' : 'https://admin.one.example.com' ,
256+ },
257+ {
258+ 'region' : 'two' ,
259+ 'publicURL' : 'https://public.two.example.com' ,
260+ 'internalURL' : 'https://internal.two.example.com' ,
261+ 'adminURL' : 'https://admin.two.example.com' ,
262+ },
263+ {
264+ 'region' : None ,
265+ 'publicURL' : 'https://public.none.example.com' ,
266+ 'internalURL' : 'https://internal.none.example.com' ,
267+ 'adminURL' : 'https://admin.none.example.com' ,
268+ },
269+ ],
270+ }
271+ # Overwrite default attributes.
272+ catalog_info .update (attrs )
273+
274+ catalog = fakes .FakeResource (
275+ info = copy .deepcopy (catalog_info ),
276+ loaded = True )
277+
278+ return catalog
279+
280+
281+ class FakeProject (object ):
282+ """Fake one or more project."""
283+
284+ @staticmethod
285+ def create_one_project (attrs = None ):
286+ """Create a fake project.
287+
288+ :param Dictionary attrs:
289+ A dictionary with all attributes
290+ :return:
291+ A FakeResource object, with id, name, and so on
292+ """
293+
294+ attrs = attrs or {}
295+
296+ # set default attributes.
297+ project_info = {
298+ 'id' : 'project-id' + uuid .uuid4 ().hex ,
299+ 'name' : 'project-name' + uuid .uuid4 ().hex ,
300+ 'description' : 'project_description' ,
301+ 'enabled' : True ,
302+ }
303+ project_info .update (attrs )
304+
305+ project = fakes .FakeResource (info = copy .deepcopy (project_info ),
306+ loaded = True )
307+ return project
308+
309+ @staticmethod
310+ def create_projects (attrs = None , count = 2 ):
311+ """Create multiple fake projects.
312+
313+ :param Dictionary attrs:
314+ A dictionary with all attributes
315+ :param int count:
316+ The number of projects to fake
317+ :return:
318+ A list of FakeResource objects faking the projects
319+ """
320+ projects = []
321+ for i in range (0 , count ):
322+ projects .append (FakeProject .create_one_project (attrs ))
323+
324+ return projects
325+
326+
327+ class FakeEndpoint (object ):
328+ """Fake one or more endpoint."""
329+
330+ @staticmethod
331+ def create_one_endpoint (attrs = None ):
332+ """Create a fake agent.
333+
334+ :param Dictionary attrs:
335+ A dictionary with all attributes
336+ :return:
337+ A FakeResource object, with id, name, region, and so on
338+ """
339+
340+ attrs = attrs or {}
341+
342+ # set default attributes.
343+ endpoint_info = {
344+ 'service_name' : SERVICE_NAME ,
345+ 'adminurl' : 'http://endpoint_adminurl' ,
346+ 'region' : 'endpoint_region' ,
347+ 'internalurl' : 'http://endpoint_internalurl' ,
348+ 'service_type' : 'service_type' ,
349+ 'id' : 'endpoint-id-' + uuid .uuid4 ().hex ,
350+ 'publicurl' : 'http://endpoint_publicurl' ,
351+ 'service_id' : SERVICE_ID ,
352+
353+ }
354+ endpoint_info .update (attrs )
355+
356+ endpoint = fakes .FakeResource (info = copy .deepcopy (endpoint_info ),
357+ loaded = True )
358+ return endpoint
359+
360+ @staticmethod
361+ def create_endpoints (attrs = None , count = 2 ):
362+ """Create multiple fake endpoints.
363+
364+ :param Dictionary attrs:
365+ A dictionary with all attributes
366+ :param int count:
367+ The number of endpoints to fake
368+ :return:
369+ A list of FakeResource objects faking the endpoints
370+ """
371+ endpoints = []
372+ for i in range (0 , count ):
373+ endpoints .append (FakeEndpoint .create_one_endpoint (attrs ))
374+
375+ return endpoints
376+
377+
378+ class FakeService (object ):
379+ """Fake one or more service."""
380+
381+ @staticmethod
382+ def create_one_service (attrs = None ):
383+ """Create a fake service.
384+
385+ :param Dictionary attrs:
386+ A dictionary with all attributes
387+ :return:
388+ A FakeResource object, with id, name, type, and so on
389+ """
390+
391+ attrs = attrs or {}
392+
393+ # set default attributes.
394+ service_info = {
395+ 'id' : SERVICE_ID ,
396+ 'name' : SERVICE_NAME ,
397+ 'description' : 'service_description' ,
398+ 'type' : 'service_type' ,
399+
400+ }
401+ service_info .update (attrs )
402+
403+ service = fakes .FakeResource (info = copy .deepcopy (service_info ),
404+ loaded = True )
405+ return service
406+
407+ @staticmethod
408+ def create_services (attrs = None , count = 2 ):
409+ """Create multiple fake services.
410+
411+ :param Dictionary attrs:
412+ A dictionary with all attributes
413+ :param int count:
414+ The number of services to fake
415+ :return:
416+ A list of FakeResource objects faking the services
417+ """
418+ services = []
419+ for i in range (0 , count ):
420+ services .append (FakeService .create_one_service (attrs ))
421+
422+ return services
423+
424+
425+ class FakeRole (object ):
426+ """Fake one or more role."""
427+
428+ @staticmethod
429+ def create_one_role (attrs = None ):
430+ """Create a fake role.
431+
432+ :param Dictionary attrs:
433+ A dictionary with all attributes
434+ :return:
435+ A FakeResource object, with id, name, and so on
436+ """
437+
438+ attrs = attrs or {}
439+
440+ # set default attributes.
441+ role_info = {
442+ 'id' : 'role-id' + uuid .uuid4 ().hex ,
443+ 'name' : 'role-name' + uuid .uuid4 ().hex ,
444+ }
445+ role_info .update (attrs )
446+
447+ role = fakes .FakeResource (info = copy .deepcopy (role_info ),
448+ loaded = True )
449+ return role
450+
451+ @staticmethod
452+ def create_roles (attrs = None , count = 2 ):
453+ """Create multiple fake roles.
454+
455+ :param Dictionary attrs:
456+ A dictionary with all attributes
457+ :param int count:
458+ The number of roles to fake
459+ :return:
460+ A list of FakeResource objects faking the roles
461+ """
462+ roles = []
463+ for i in range (0 , count ):
464+ roles .append (FakeRole .create_one_role (attrs ))
465+
466+ return roles
0 commit comments