Esempio n. 1
0
    def test_get_template_contexts(self):
        with self.assertRaises(StopIteration):
            next(get_template_contexts('k8s/fixtures/empty.yaml'))

        with self.assertRaises(RuntimeError) as context:
            next(get_template_contexts('k8s/fixtures/nokind.yaml'))
        self.assertTrue(
            'Field "kind" not found (or empty) in file "k8s/fixtures/nokind.yaml"'
            in str(context.exception), context.exception)

        with self.assertRaises(RuntimeError) as context:
            next(get_template_contexts('k8s/fixtures/nometadata.yaml'))
        self.assertTrue(
            'Field "metadata" not found (or empty) in file "k8s/fixtures/nometadata.yaml"'
            in str(context.exception), context.exception)

        with self.assertRaises(RuntimeError) as context:
            next(get_template_contexts('k8s/fixtures/nometadataname.yaml'))
        self.assertTrue(
            'Field "metadata->name" not found (or empty) in file "k8s/fixtures/nometadataname.yaml"'
            in str(context.exception), context.exception)

        context = next(get_template_contexts('k8s/fixtures/valid.yaml'))
        self.assertEqual(context.get('kind'), 'Service')
        self.assertEqual(context.get('apiVersion'), 'v1')
        self.assertEqual(context.get('metadata').get('name'), 'my-service')
        self.assertEqual(
            context.get('spec').get('selector').get('app'), 'my-app')

        context = next(
            get_template_contexts('k8s/fixtures/deployment_wo_replicas.yaml'))
        self.assertEqual(context.get('spec').get('replicas'), 1)
Esempio n. 2
0
 def _destroy_all(self, file_path):
     for template_body in get_template_contexts(file_path):
         self._destroy(template_body, file_path)
 def run(self, file_path):
     for template_body in get_template_contexts(file_path):
         self._is_deprecated(
             template_body.get('apiVersion'),
             template_body.get('kind'),
         )