Ejemplo n.º 1
0
    def testSuccess(self):
        get_response1 = {
            'RegionId': 'r',
            'SecurityGroupId': 'sg',
            'Description': 'd',
            'Permissions': {'Permission': [
                {
                    'IpProtocol': 'TCP',
                    'PortRange': '22/22',
                    'SourceCidrIp': '2.2.2.2/32',
                    'Policy': 'Accept',
                    'NicType': 'internet'
                },
                {
                    'IpProtocol': 'TCP',
                    'PortRange': '22/22',
                    'SourceCidrIp': '1.1.1.1/32',
                    'Policy': 'Reject',
                    'NicType': 'internet'
                }]}
        }
        get_response2 = {
            'RegionId': 'r',
            'SecurityGroupId': 'sg',
            'Description': 'd',
            'Permissions': {'Permission': [
                {
                    'IpProtocol': 'TCP',
                    'PortRange': '22/22',
                    'SourceGroupId': 'sg2',
                    'Policy': 'Accept',
                    'NicType': 'intranet'
                },
                {
                    'IpProtocol': 'TCP',
                    'PortRange': '22/22',
                    'SourceCidrIp': '3.3.3.3/32',
                    'Policy': 'Reject',
                    'NicType': 'intranet'
                }]}
        }
        p1 = ecs.SecurityGroupPermission('TCP', '22/22', '2.2.2.2/32', None,
                                         'Accept', 'internet')
        p2 = ecs.SecurityGroupPermission('TCP', '22/22', '1.1.1.1/32', None,
                                         'Reject', 'internet')
        p3 = ecs.SecurityGroupPermission('TCP', '22/22', None, 'sg2',
                                         'Accept', 'intranet')
        p4 = ecs.SecurityGroupPermission('TCP', '22/22', '3.3.3.3/32', None,
                                         'Reject', 'intranet')
        self.conn.get({'Action': 'DescribeSecurityGroupAttribute',
                       'SecurityGroupId': 'sg',
                       'NicType': 'internet'}).AndReturn(get_response1)
        self.conn.get({'Action': 'DescribeSecurityGroupAttribute',
                       'SecurityGroupId': 'sg',
                       'NicType': 'intranet'}).AndReturn(get_response2)

        self.mox.ReplayAll()
        self.assertEqual(ecs.SecurityGroup('r', 'sg', 'd', [p1, p2, p3, p4]),
                         self.conn.get_security_group('sg'))
        self.mox.VerifyAll()
Ejemplo n.º 2
0
 def testNotEqual(self):
     p1 = ecs.SecurityGroupPermission('TCP', '22/22', '1.1.1.1/32', None,
                                      'Accept', 'internet')
     p2 = ecs.SecurityGroupPermission('TCP', '22/22', '1.1.1.1/32', None,
                                      'Reject', 'internet')
     sg1 = ecs.SecurityGroup('r', 'sg1', 'd', [p1])
     sg2 = ecs.SecurityGroup('r', 'sg1', 'd', [p2])
     self.assertNotEqual(sg1, sg2)
Ejemplo n.º 3
0
 def testRepr(self):
     p1 = ecs.SecurityGroupPermission('TCP', '22/22', '1.1.1.1/32', None,
                                      'Accept', 'internet')
     self.assertTrue(
         repr(p1).startswith(
             u'<SecurityGroupPermission Accept TCP 22/22 from 1.1.1.1/32 at'
         ))
Ejemplo n.º 4
0
 def testRepr(self):
     p1 = ecs.SecurityGroupPermission('TCP', '22/22', '1.1.1.1/32', None,
                                      'Accept', 'internet')
     sg1 = ecs.SecurityGroup('r', 'sg1', 'd', [p1])
     self.assertTrue(repr(sg1).startswith(
         u'<SecurityGroup sg1, d at'))
Ejemplo n.º 5
0
 def testNotEqual(self):
     p1 = ecs.SecurityGroupPermission('TCP', '22/22', '1.1.1.1/32', None,
                                      'Accept', 'internet')
     p2 = ecs.SecurityGroupPermission('TCP', '22/22', '1.1.1.1/32', None,
                                      'Reject', 'internet')
     self.assertNotEqual(p1, p2)