def test_get_provider_opened_ports_unknown_instance(self): """Verify open port op will use the correct EC2 API.""" self.ec2.describe_security_groups("juju-moon-machine-1") self.mocker.result(fail(self.get_ec2_error("i-foobar"))) self.mocker.replay() provider = self.get_provider() machine = ProviderMachine("i-foobar", "x1.example.com") ex = yield self.assertFailure( get_provider_opened_ports(provider, machine, "machine-1"), ProviderInteractionError) self.assertEqual( str(ex), "Unexpected EC2Error getting open ports on machine i-foobar: " "The instance ID 'i-foobar' does not exist")
def test_get_provider_opened_ports(self): """Verify correct parse of IP perms from describe_security_group.""" self.ec2.describe_security_groups("juju-moon-machine-1") self.mocker.result(succeed([ SecurityGroup( "juju-%s-machine-1" % self.env_name, "a security group name", ips=[ IPPermission("udp", "53", "53", "0.0.0.0/0"), IPPermission("tcp", "80", "80", "0.0.0.0/0"), # The range 8080-8082 will be ignored IPPermission("tcp", "8080", "8082", "0.0.0.0/0"), # Ignore permissions that are not 0.0.0.0/0 IPPermission("tcp", "443", "443", "10.1.2.3") ])])) self.mocker.replay() provider = self.get_provider() machine = ProviderMachine( "i-foobar", "x1.example.com") opened_ports = yield get_provider_opened_ports( provider, machine, "machine-1") self.assertEqual(opened_ports, set([(53, "udp"), (80, "tcp")]))
def test_get_provider_opened_ports(self): """Verify correct parse of IP perms from describe_security_group.""" self.ec2.describe_security_groups("juju-moon-machine-1") self.mocker.result( succeed([ SecurityGroup( "juju-%s-machine-1" % self.env_name, "a security group name", ips=[ IPPermission("udp", "53", "53", "0.0.0.0/0"), IPPermission("tcp", "80", "80", "0.0.0.0/0"), # The range 8080-8082 will be ignored IPPermission("tcp", "8080", "8082", "0.0.0.0/0"), # Ignore permissions that are not 0.0.0.0/0 IPPermission("tcp", "443", "443", "10.1.2.3") ]) ])) self.mocker.replay() provider = self.get_provider() machine = ProviderMachine("i-foobar", "x1.example.com") opened_ports = yield get_provider_opened_ports(provider, machine, "machine-1") self.assertEqual(opened_ports, set([(53, "udp"), (80, "tcp")]))