@@ -462,28 +462,76 @@ def create_security_groups(attrs={}, methods={}, count=2):
462462 security_groups = []
463463 for i in range (0 , count ):
464464 security_groups .append (
465- FakeRouter .create_one_security_group (attrs , methods ))
465+ FakeSecurityGroup .create_one_security_group (attrs , methods ))
466466
467467 return security_groups
468468
469+
470+ class FakeSecurityGroupRule (object ):
471+ """Fake one or more security group rules."""
472+
469473 @staticmethod
470- def get_security_groups ( security_groups = None , count = 2 ):
471- """Get an iterable MagicMock object with a list of faked security groups .
474+ def create_one_security_group_rule ( attrs = {}, methods = {} ):
475+ """Create a fake security group rule .
472476
473- If security group list is provided, then initialize the Mock object
474- with the list. Otherwise create one.
477+ :param Dictionary attrs:
478+ A dictionary with all attributes
479+ :param Dictionary methods:
480+ A dictionary with all methods
481+ :return:
482+ A FakeResource object, with id, name, etc.
483+ """
484+ # Set default attributes.
485+ security_group_rule_attrs = {
486+ 'description' : 'security-group-rule-desc-' + uuid .uuid4 ().hex ,
487+ 'direction' : 'ingress' ,
488+ 'ethertype' : 'IPv4' ,
489+ 'id' : 'security-group-rule-id-' + uuid .uuid4 ().hex ,
490+ 'name' : 'security-group-rule-name-' + uuid .uuid4 ().hex ,
491+ 'port_range_max' : None ,
492+ 'port_range_min' : None ,
493+ 'protocol' : None ,
494+ 'remote_group_id' : 'remote-security-group-id-' + uuid .uuid4 ().hex ,
495+ 'remote_ip_prefix' : None ,
496+ 'security_group_id' : 'security-group-id-' + uuid .uuid4 ().hex ,
497+ 'tenant_id' : 'project-id-' + uuid .uuid4 ().hex ,
498+ }
499+
500+ # Overwrite default attributes.
501+ security_group_rule_attrs .update (attrs )
475502
476- :param List security groups:
477- A list of FakeResource objects faking security groups
503+ # Set default methods.
504+ security_group_rule_methods = {}
505+
506+ # Overwrite default methods.
507+ security_group_rule_methods .update (methods )
508+
509+ security_group_rule = fakes .FakeResource (
510+ info = copy .deepcopy (security_group_rule_attrs ),
511+ methods = copy .deepcopy (security_group_rule_methods ),
512+ loaded = True )
513+ return security_group_rule
514+
515+ @staticmethod
516+ def create_security_group_rules (attrs = {}, methods = {}, count = 2 ):
517+ """Create multiple fake security group rules.
518+
519+ :param Dictionary attrs:
520+ A dictionary with all attributes
521+ :param Dictionary methods:
522+ A dictionary with all methods
478523 :param int count:
479- The number of security groups to fake
524+ The number of security group rules to fake
480525 :return:
481- An iterable Mock object with side_effect set to a list of faked
482- security groups
526+ A list of FakeResource objects faking the security group rules
483527 """
484- if security_groups is None :
485- security_groups = FakeRouter .create_security_groups (count )
486- return mock .MagicMock (side_effect = security_groups )
528+ security_group_rules = []
529+ for i in range (0 , count ):
530+ security_group_rules .append (
531+ FakeSecurityGroupRule .create_one_security_group_rule (
532+ attrs , methods ))
533+
534+ return security_group_rules
487535
488536
489537class FakeSubnet (object ):
0 commit comments