def new( self, protocolService: ProtocolService, user_script: str, vpc, distro=None, ): keypairname = None if protocolService.is_have_ssh(): keypairname = AWSUtils().get_key_pair_name() if not keypairname: raise Exception( 'No keypair found to assign. You need it to access through ssh.' ) region = self.aws_client.meta.region_name aws_resource = boto3.resource('ec2', region_name=region) subnet = VPC_Client().get_first_subnet(vpc) return AwsClientUtils().create_new_instance_resource( aws_resource, region, keypairname, user_script, subnet, distro)
def test_is_have_desktop_true_2(self): protocolService = ProtocolService("with-desktop") self.assertTrue(protocolService.is_have_desktop())
def test_ensure_3306_5(self): protocolService = ProtocolService("") protocolService.ensure_port_3306() self.assertTrue(3306 in protocolService.get_ports())
def test_ensure_3306_2(self): protocolService = ProtocolService("with-database") protocolService.ensure_port_3306() self.assertTrue(3306 in protocolService.get_ports())
def test_is_have_database_true_2(self): protocolService = ProtocolService("with-database") self.assertTrue(protocolService.is_have_database())
def test_is_have_https_true_2(self): protocolService = ProtocolService("with-https") self.assertTrue(protocolService.is_have_https())
def test_ensure_443_4(self): protocolService = ProtocolService("with-https,with-ssh") protocolService.ensure_port_443() self.assertTrue(443 in protocolService.get_ports())
def test_ensure_80_4(self): protocolService = ProtocolService("with-http,with-ssh") protocolService.ensure_port_80() self.assertTrue(80 in protocolService.get_ports())
def test_ensure_80_5(self): protocolService = ProtocolService("") protocolService.ensure_port_80() self.assertTrue(80 in protocolService.get_ports())
def test_is_have_http_true(self): protocolService = ProtocolService("with-ssh,with-http") self.assertTrue(protocolService.is_have_http())
def test_is_have_http_false_3(self): protocolService = ProtocolService("") self.assertFalse(protocolService.is_have_http())
def test_port_from_http(self): protocolServoce = ProtocolService("with-http") self.assertEqual(80, protocolServoce.get_ports()[0])
def test_ensure_3389_3(self): protocolService = ProtocolService("with-desktop") protocolService.ensure_port_3389() self.assertTrue(3389 in protocolService.get_ports())
def test_ensure_3389(self): protocolService = ProtocolService() protocolService.ensure_port_3389() self.assertTrue(3389 in protocolService.get_ports())
def test_execption_wrong_argument(self): wrong_argument = "some-invalid" with self.assertRaises(Exception): ProtocolService(wrong_argument)
def test_get_zero_element_none(self): protocolServoce = ProtocolService() self.assertEqual(0, len(protocolServoce.get_ports()))
def test_port_from_desktop(self): protocolService = ProtocolService("with-https") self.assertEqual(443, protocolService.get_ports()[0])
def test_port_both_options(self): protocolService = ProtocolService("with-ssh,with-http") returned_ports = protocolService.get_ports() self.assertEqual(22, returned_ports[0]) self.assertEqual(80, returned_ports[1])
def test_ensure_443_3(self): protocolService = ProtocolService("with-desktop") protocolService.ensure_port_443() self.assertTrue(443 in protocolService.get_ports())
def test_port_three_options(self): protocolService = ProtocolService("with-ssh,with-http,with-database") returned_ports = protocolService.get_ports() self.assertEqual(22, returned_ports[0]) self.assertEqual(80, returned_ports[1]) self.assertEqual(3306, returned_ports[2])
def test_ensure_443_5(self): protocolService = ProtocolService("") protocolService.ensure_port_443() self.assertTrue(443 in protocolService.get_ports())
def test_one_option_wrong(self): one_option_wrong = "with-ssh,with-cassandra" with self.assertRaises(Exception): ProtocolService(one_option_wrong)
def test_port_from_database(self): protocolServoce = ProtocolService("with-database") self.assertEqual(3306, protocolServoce.get_ports()[0])
def test_three_options_one_wrong(self): three_options = "with-ssh,with-http,with-cassandra" with self.assertRaises(Exception): ProtocolService(three_options)
def test_ensure_3306_is_not_empty(self): protocolService = ProtocolService(None) protocolService.ensure_port_3306() self.assertTrue(protocolService.is_not_empty())
def test_is_not_empty_false(self): protocolService = ProtocolService() self.assertFalse(protocolService.is_not_empty())
def test_ensure_3306_4(self): protocolService = ProtocolService("with-http,with-ssh") protocolService.ensure_port_3306() self.assertTrue(3306 in protocolService.get_ports())
def test_is_not_empty_true2(self): protocolService = ProtocolService("with-ssh,with-http") self.assertTrue(protocolService.is_not_empty())
def test_get_one_element(self): protocolServoce = ProtocolService("with-database") self.assertEqual(1, len(protocolServoce.get_ports()))
def test_port_from_desktop(self): protocolService = ProtocolService("with-desktop") self.assertEqual(3389, protocolService.get_ports()[0])