Example #1
0
 def packet_test_scenario(
     self,
     zone1,
     zone2,
     sec_group1,
     sec_group_2,
     vpc1,
     vpc2,
     subnet1,
     subnet2,
     use_private,
     protocol,
     pkt_count=5,
     retries=2,
     verbose=None,
 ):
     vpc = self.default_vpc
     results = {}
     start = time.time()
     if verbose is None:
         if self.args.log_level == "DEBUG":
             verbose = 2
         else:
             verbose = 0
     sec_group = self.get_test_security_groups(vpc=vpc, count=1, rules=self.DEFAULT_RULES)[0]
     try:
         for zone in self.zones:
             self.log.info('STARTING PACKET TEST AGAINST ZONE:"{0}"'.format(zone))
             ins1, ins2 = self.get_test_instances(zone=zone, group_id=sec_group.id, count=2)
             for retry in xrange(1, retries + 1):
                 try:
                     pkt_dict = packet_test(
                         sender_ssh=ins1.ssh, receiver_ssh=ins2.ssh, protocol=1, count=pkt_count, verbose=verbose
                     )
                     if pkt_dict.get("error", None) or (pkt_dict.get("count") != pkt_count):
                         raise RuntimeError("Packet test failed, results:{0}".format(pkt_dict))
                     self.log.debug("Results for Zone: {0}\n{1}".format(zone, pkt_dict))
                     results[zone] = pkt_dict
                 except Exception as PE:
                     self.log.error(
                         "{0}\nPacket Test for zone: {1} failed attempt:{2}/{3}".format(
                             get_traceback(), zone, retry, retries
                         )
                     )
                     wait = 30 - int(time.time() - start)
                     if wait > 0:
                         self.log.debug('Waiting "{0}" seconds to retry packet test'.format(wait))
                         time.sleep(wait)
             if zone not in results:
                 raise RuntimeError("Failed packet test for zone: {0}".format(zone))
     finally:
         for zone, pkt_dict in results.iteritems():
             self.show_packet_test_results(
                 pkt_dict, header="test2_icmp_packet_test_same_az_and_sg. " "Zone:{0}".format(zone)
             )
     self.log.info("test2_icmp_packet_test_same_az_and_sg passed")
Example #2
0
 def packet_test_scenario(self, zone1, zone2, sec_group1, sec_group_2, vpc1, vpc2,
                          subnets, use_private, protocol, pkt_count=5, retries=2, verbose=None):
     """
     This method is intended to be used as the core test method. It can be fed different
     sets of params each representing a different test scenario. This should allow for
     dictionaries of params to be autogenerated and fed to this test method forming a
     auto-generated test matrix. Used with cli_runner each param set can be ran as a testunit
     providing formatted results. This method should also provide a dict of results for
     additional usage.
     :param zone1: zone name
     :param zone2: zone name
     :param sec_group1: group obj or id
     :param sec_group_2: group obj or id
     :param vpc1: vpc obj or id
     :param vpc2: vpc obj or id
     :param subnet1: subnet obj or id
     :param subnet2: subnet obj or id
     :param use_private: bool, to use private addressing or not
     :param protocol: a dict to be fed to 'packet_test'. Example:{'protocol': ICMP, 'count': pkt_count}
     :param pkt_count: number of packets
     :param retries: number of retries
     :param verbose: bool, for verbose output
     :return dict of results (tbd)
     """
     vpc = self.default_vpc
     results = {}
     start = time.time()
     if verbose is None:
         if self.args.log_level == 'DEBUG':
             verbose = 2
         else:
             verbose = 0
     sec_group = self.get_test_security_groups(vpc=vpc, count=1, rules=self.DEFAULT_RULES)[0]
     try:
         for zone in self.zones:
             self.log.info('STARTING PACKET TEST AGAINST ZONE:"{0}"'.format(zone))
             ins1, ins2 = self.get_test_instances(zone=zone, group_id=sec_group.id, count=2)
             for retry in xrange(1, retries + 1):
                 try:
                     pkt_dict = packet_test(sender_ssh=ins1.ssh, receiver_ssh=ins2.ssh,
                                            protocol=1, count=pkt_count, verbose=verbose)
                     if pkt_dict.get('error', None) or (pkt_dict.get('count') != pkt_count):
                         raise RuntimeError('Packet test failed, results:{0}'.format(pkt_dict))
                     self.log.debug("Results for Zone: {0}\n{1}".format(zone, pkt_dict))
                     results[zone] = pkt_dict
                 except Exception as PE:
                     self.log.error("{0}\nPacket Test for zone: {1} failed attempt:{2}/{3}"
                                    .format(get_traceback(), zone, retry, retries))
                     wait = 30 - int(time.time()-start)
                     if wait > 0:
                         self.log.debug('Waiting "{0}" seconds to retry packet test'.format(wait))
                         time.sleep(wait)
             if zone not in results:
                 raise RuntimeError('Failed packet test for zone: {0}'.format(zone))
     finally:
         for zone, pkt_dict in results.iteritems():
             self.show_packet_test_results(pkt_dict,
                                           header='test2_icmp_packet_test_same_az_and_sg. '
                                                  'Zone:{0}'.format(zone))
     self.log.info('test2_icmp_packet_test_same_az_and_sg passed')
     # todo decide up results format
     return results