def test_activates(self): """Ensures that the instance template revision is activated.""" template_cfg = config_pb2.InstanceTemplateConfig.InstanceTemplate( base_name='base-name', ) expected_active_key = parse.get_instance_template_revision_key(template_cfg) instance_template = models.InstanceTemplate() self.failUnless(parse.ensure_instance_template_revision_active( template_cfg, instance_template)) self.assertEqual(instance_template.active, expected_active_key)
def test_activates(self): """Ensures that the instance template revision is activated.""" template_cfg = config_pb2.InstanceTemplateConfig.InstanceTemplate( base_name='base-name', ) expected_active_key = parse.get_instance_template_revision_key( template_cfg) instance_template = models.InstanceTemplate() self.failUnless( parse.ensure_instance_template_revision_active( template_cfg, instance_template)) self.assertEqual(instance_template.active, expected_active_key)
def test_drains_and_activates(self): """Ensures that the active instance template revision is drained.""" template_cfg = config_pb2.InstanceTemplateConfig.InstanceTemplate( base_name='base-name', ) expected_active_key = parse.get_instance_template_revision_key( template_cfg) instance_template = models.InstanceTemplate(active=ndb.Key( models.InstanceTemplateRevision, 'fake-key'), ) self.failUnless( parse.ensure_instance_template_revision_active( template_cfg, instance_template)) self.assertEqual(instance_template.active, expected_active_key) self.assertEqual(instance_template.drained[0].id(), 'fake-key')
def test_drains_and_activates(self): """Ensures that the active instance template revision is drained.""" template_cfg = config_pb2.InstanceTemplateConfig.InstanceTemplate( base_name='base-name', ) expected_active_key = parse.get_instance_template_revision_key(template_cfg) instance_template = models.InstanceTemplate( active=ndb.Key(models.InstanceTemplateRevision, 'fake-key'), ) self.failUnless(parse.ensure_instance_template_revision_active( template_cfg, instance_template)) self.assertEqual(instance_template.active, expected_active_key) self.assertEqual(instance_template.drained[0].id(), 'fake-key')
def test_already_active(self): """Ensures that the active instance template revision remains active.""" template_cfg = config_pb2.InstanceTemplateConfig.InstanceTemplate( base_name='base-name', ) expected_active_key = parse.get_instance_template_revision_key(template_cfg) instance_template = models.InstanceTemplate( active=parse.get_instance_template_revision_key(template_cfg), drained=[ ndb.Key(models.InstanceTemplateRevision, 'fake-key'), ], ) self.failIf(parse.ensure_instance_template_revision_active( template_cfg, instance_template)) self.assertEqual(instance_template.active, expected_active_key) self.assertEqual(len(instance_template.drained), 1) self.assertEqual(instance_template.drained[0].id(), 'fake-key')
def test_already_active(self): """Ensures that the active instance template revision remains active.""" template_cfg = config_pb2.InstanceTemplateConfig.InstanceTemplate( base_name='base-name', ) expected_active_key = parse.get_instance_template_revision_key( template_cfg) instance_template = models.InstanceTemplate( active=parse.get_instance_template_revision_key(template_cfg), drained=[ ndb.Key(models.InstanceTemplateRevision, 'fake-key'), ], ) self.failIf( parse.ensure_instance_template_revision_active( template_cfg, instance_template)) self.assertEqual(instance_template.active, expected_active_key) self.assertEqual(len(instance_template.drained), 1) self.assertEqual(instance_template.drained[0].id(), 'fake-key')
def test_reactivates(self): """Ensures that the drained instance template revision is reactivated.""" template_cfg = config_pb2.InstanceTemplateConfig.InstanceTemplate( base_name='base-name', ) expected_active_key = parse.get_instance_template_revision_key( template_cfg) instance_template = models.InstanceTemplate(drained=[ ndb.Key(models.InstanceTemplateRevision, 'fake-key-1'), parse.get_instance_template_revision_key(template_cfg), ndb.Key(models.InstanceTemplateRevision, 'fake-key-2'), ], ) self.failUnless( parse.ensure_instance_template_revision_active( template_cfg, instance_template)) self.assertEqual(instance_template.active, expected_active_key) self.assertEqual(len(instance_template.drained), 2) self.assertEqual(instance_template.drained[0].id(), 'fake-key-1') self.assertEqual(instance_template.drained[1].id(), 'fake-key-2')
def test_reactivates(self): """Ensures that the drained instance template revision is reactivated.""" template_cfg = config_pb2.InstanceTemplateConfig.InstanceTemplate( base_name='base-name', ) expected_active_key = parse.get_instance_template_revision_key(template_cfg) instance_template = models.InstanceTemplate( drained=[ ndb.Key(models.InstanceTemplateRevision, 'fake-key-1'), parse.get_instance_template_revision_key(template_cfg), ndb.Key(models.InstanceTemplateRevision, 'fake-key-2'), ], ) self.failUnless(parse.ensure_instance_template_revision_active( template_cfg, instance_template)) self.assertEqual(instance_template.active, expected_active_key) self.assertEqual(len(instance_template.drained), 2) self.assertEqual(instance_template.drained[0].id(), 'fake-key-1') self.assertEqual(instance_template.drained[1].id(), 'fake-key-2')