def testIsProductionSite(self): # Production checks os.environ['SITE_REGEX'] = '^[a-z]{3}[0-9c]{2}$' self.assertTrue(pc.is_production_site('nuq01')) self.assertTrue(pc.is_production_site('nuq99')) self.assertTrue(pc.is_production_site('tun05')) self.assertTrue(pc.is_production_site('lax0c')) self.assertTrue( pc.is_production_site('TUN05'), ('production style site names are considered production even when ' 'uppercase')) self.assertFalse(pc.is_production_site('')) self.assertFalse(pc.is_production_site('foo')) self.assertFalse( pc.is_production_site('lga123'), 'Sites with too many numbers are not production sites.') self.assertFalse(pc.is_production_site('lga0t'), 'Sites with a t suffix are not production sites.') # Sandbox checks os.environ['SITE_REGEX'] = '^[a-z]{3}[0-9]t$' self.assertTrue( pc.is_production_site('lga0t'), 'Sites with a t suffix _are_ production in mlab-sandbox project.')
def testIsProductionSite(self): self.assertTrue(pc.is_production_site('nuq01')) self.assertTrue(pc.is_production_site('nuq99')) self.assertTrue(pc.is_production_site('tun05')) self.assertTrue(pc.is_production_site('lax0c')) self.assertTrue( pc.is_production_site('TUN05'), ('production style site names are considered production even when ' 'uppercase')) self.assertFalse(pc.is_production_site('')) self.assertFalse(pc.is_production_site('foo')) self.assertFalse( pc.is_production_site('lga123'), 'Sites with too many numbers are not production sites.') self.assertFalse( pc.is_production_site('lga01t'), 'Sites with a t suffix are not production sites.')
def _is_valid_site(cls, site): """Determines whether a site represents a valid, production M-Lab site. Args: site: A dictionary representing info for a particular site as it appears on Nagios. Returns: True if the site is a valid, production M-Lab site. """ # TODO(claudiu) Need more robust validation. for field in cls.REQUIRED_FIELDS: if field not in site: logging.error('%s does not have the required field %s.', json.dumps(site), field) return False if not production_check.is_production_site(site[cls.SITE_FIELD]): logging.info('Ignoring non-production site: %s', site[cls.SITE_FIELD]) return False return True