Esempio n. 1
0
 def delete_site():
     delete_command = "{0} {1} delete --pk {2}".format(
         EXEC, 'SITE', self.vlan_pk)
     ret, errors, rc = call_to_json(delete_command)
     if errors:
         self.fail(errors)
     self.assertEqual(0, rc)
     self.assertTrue('http_status' in ret)
     self.assertEqual(ret['http_status'], 204)
Esempio n. 2
0
 def delete_vlan():
     delete_command = "{0} {1} delete --pk {2}".format(
         EXEC, 'VLAN', self.vlan_pk)
     ret, errors, rc = call_to_json(delete_command)
     if errors:
         self.fail(errors)
     self.assertEqual(0, rc)
     self.assertTrue('http_status' in ret)
     self.assertEqual(ret['http_status'], 204)
Esempio n. 3
0
 def do_test_setup(self, test_case):
     command = [EXEC, DispatchSystem.dtype, 'create']
     for add_arg, extract_arg, tm in DispatchSystem.create_args:
         command.append(test_method_to_params(tm()))
     command_str = ' '.join(command)
     ret, errors, rc = call_to_json(command_str)
     if errors:
         test_case.fail(errors)
     return ret['pk']
Esempio n. 4
0
 def do_test_setup(self, test_case):
     command = [EXEC, DispatchSystem.dtype, 'create']
     for add_arg, extract_arg, tm in DispatchSystem.create_args:
         command.append(test_method_to_params(tm()))
     command_str = ' '.join(command)
     ret, errors, rc = call_to_json(command_str)
     if errors:
         test_case.fail(errors)
     return ret['pk']
            def lookup_kv():
                ret, errors, rc = call_to_json(detail_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 200)
                self.assertTrue('kv_pk' in ret)
                self.assertEqual(ret['kv_pk'], kv_pk)
Esempio n. 6
0
            def test_csv_export():
                expected_status, command = commands[2]
                ret, errors, rc = call_to_json(command)

                if errors:
                    self.fail(errors)

                self.assertEqual(0, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], expected_status)
            def delete_kv():
                delete_command = _("{0} {1} delete --kv-pk {2}".format(
                    EXEC, dispatch.dtype, kv_pk)
                )
                ret, errors, rc = call_to_json(delete_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)
                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 204)

                # Detail the object (expect a 404)
                ret, errors, rc = call_to_json(detail_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(1, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 404)
                self.assertFalse('kv_pk' in ret)
Esempio n. 8
0
 def do_test_setup(self, test_case):
     command = [EXEC, DispatchNetwork.dtype, 'create']
     for add_arg, extract_arg, tm in DispatchNetwork.create_args:
         if tm()[0] in ('site-pk', 'vlan-pk'):
             continue
         command.append(test_method_to_params(tm()))
     command_str = ' '.join(command)
     ret, errors, rc = call_to_json(command_str)
     if errors:
         test_case.fail(errors)
     return ret['pk']
Esempio n. 9
0
 def do_test_setup(self, test_case):
     command = [EXEC, DispatchNetwork.dtype, 'create']
     for add_arg, extract_arg, tm in DispatchNetwork.create_args:
         if tm()[0] in ('site-pk', 'vlan-pk'):
             continue
         command.append(test_method_to_params(tm()))
     command_str = ' '.join(command)
     ret, errors, rc = call_to_json(command_str)
     if errors:
         test_case.fail(errors)
     return ret['pk']
Esempio n. 10
0
            def delete_hw():
                # Create a HW
                command = [EXEC, DispatchHW.dtype, 'create']
                for add_arg, extract_arg, tm in DispatchHW.create_args:
                    command.append(test_method_to_params(tm()))
                command_str = ' '.join(command)
                # lol, we are jinja2. evaluate our placeholder
                command_str = command_str.replace(
                    '{{ sreg_pk }}', str(sreg_pk))
                local_ret, local_errors, local_rc = call_to_json(command_str)

                if local_errors:
                    self.fail(local_errors)

                self.assertTrue('http_status' in local_ret)
                self.assertEqual(local_ret['http_status'], 201)
                self.assertTrue('pk' in local_ret)
                local_pk = local_ret['pk']

                delete_command = _("{0} {1} delete --pk {2}".format(
                    EXEC, DispatchHW.dtype, local_pk)
                )
                ret, errors, rc = call_to_json(delete_command)

                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)

                detail_command = _("{0} {1} detail --pk {2}".format(
                    EXEC, DispatchHW.dtype, local_pk)
                )
                ret, errors, rc = call_to_json(detail_command)

                if errors:
                    self.fail(errors)

                self.assertEqual(1, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 404)
                self.assertTrue('pk' not in ret)
            def update_kv():
                expected_status, command = commands[1]
                update_command_str = command.replace('{{ kv_pk }}', str(kv_pk))
                ret, errors, rc = call_to_json(update_command_str)

                if errors:
                    self.fail(errors)

                self.assertEqual(0, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 200)
Esempio n. 12
0
            def delete_sreg_causing_hw_delete():
                delete_command = _("{0} {1} delete --pk {2}".format(
                    EXEC, DispatchSREG.dtype, sreg_pk))
                ret, errors, rc = call_to_json(delete_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)

                # Make sure the SREG getting deleted caused a cascade delete
                detail_command = _("{0} {1} detail --pk {2}".format(
                    EXEC, DispatchHW.dtype, hw_pk))
                local_ret, local_errors, local_rc = call_to_json(
                    detail_command)

                if local_errors:
                    self.fail(local_errors)

                self.assertEqual(1, local_rc)

                self.assertTrue('http_status' in local_ret)
                self.assertEqual(local_ret['http_status'], 404)
                self.assertTrue('pk' not in local_ret)
            def create_kv():
                command_str = command.replace('{{ obj_pk }}', str(obj_pk))
                ret, errors, rc = call_to_json(command_str)

                if errors:
                    self.fail(errors)

                self.assertEqual(0, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], expected_status)
                self.assertTrue('kv_pk' in ret)
                return ret['kv_pk']
Esempio n. 14
0
            def hw_detail():
                # Use a closure to keep outer context more clean
                detail_command = _("{0} {1} detail --pk {2}".format(
                    EXEC, DispatchHW.dtype, hw_pk))
                ret, errors, rc = call_to_json(detail_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 200)
                self.assertTrue('pk' in ret)
                self.assertEqual(ret['pk'], hw_pk)
Esempio n. 15
0
            def hw_detail():
                # Use a closure to keep outer context more clean
                detail_command = _("{0} {1} detail --pk {2}".format(
                    EXEC, DispatchHW.dtype, hw_pk)
                )
                ret, errors, rc = call_to_json(detail_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 200)
                self.assertTrue('pk' in ret)
                self.assertEqual(ret['pk'], hw_pk)
Esempio n. 16
0
    def do_test_setup(self, test_case):
        sreg_pk = self.do_setup(DispatchSREG, test_case)

        # Create a HW
        command = [EXEC, DispatchHW.dtype, 'create']
        for add_arg, extract_arg, test_method in DispatchHW.create_args:
            command.append(test_method_to_params(test_method()))
        command_str = ' '.join(command)
        # lol, we are jinja2. evaluate our placeholder
        command_str = command_str.replace('{{ sreg_pk }}', str(sreg_pk))
        hw_ret, hw_errors, hw_rc = call_to_json(command_str)

        if hw_errors:
            test_case.fail(hw_errors)
        return hw_ret['pk']
Esempio n. 17
0
            def delete_sreg_causing_hw_delete():
                delete_command = _("{0} {1} delete --pk {2}".format(
                    EXEC, DispatchSREG.dtype, sreg_pk)
                )
                ret, errors, rc = call_to_json(delete_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)

                # Make sure the SREG getting deleted caused a cascade delete
                detail_command = _("{0} {1} detail --pk {2}".format(
                    EXEC, DispatchHW.dtype, hw_pk)
                )
                local_ret, local_errors, local_rc = call_to_json(
                    detail_command)

                if local_errors:
                    self.fail(local_errors)

                self.assertEqual(1, local_rc)

                self.assertTrue('http_status' in local_ret)
                self.assertEqual(local_ret['http_status'], 404)
                self.assertTrue('pk' not in local_ret)
Esempio n. 18
0
    def do_test_setup(self, test_case):
        sreg_pk = self.do_setup(DispatchSREG, test_case)

        # Create a HW
        command = [EXEC, DispatchHW.dtype, 'create']
        for add_arg, extract_arg, test_method in DispatchHW.create_args:
            command.append(test_method_to_params(test_method()))
        command_str = ' '.join(command)
        # lol, we are jinja2. evaluate our placeholder
        command_str = command_str.replace('{{ sreg_pk }}', str(sreg_pk))
        hw_ret, hw_errors, hw_rc = call_to_json(command_str)

        if hw_errors:
            test_case.fail(hw_errors)
        return hw_ret['pk']
            def list_kv():
                list_command = _("{0} {1} list --obj-pk {2}".format(
                    EXEC, dispatch.dtype, obj_pk)
                )
                ret, errors, rc = call_to_json(list_command)

                if errors:
                    self.fail(errors)

                self.assertEqual(0, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 200)
                self.assertTrue('kvs' in ret)
                return len(ret['kvs'])
Esempio n. 20
0
            def detail_sreg_1():
                detail_command = _("{0} {1} detail --pk {2}".format(
                    EXEC, DispatchSREG.dtype, sreg_pk))
                ret, errors, rc = call_to_json(detail_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 200)
                self.assertTrue('pk' in ret)
                self.assertEqual(ret['pk'], sreg_pk)

                self.assertTrue('hwadapter_set' in ret)
                self.assertEqual(1, len(ret['hwadapter_set']))
                self.assertEqual(hw_pk, ret['hwadapter_set'][0]['pk'])
Esempio n. 21
0
            def detail_sreg_1():
                detail_command = _("{0} {1} detail --pk {2}".format(
                    EXEC, DispatchSREG.dtype, sreg_pk)
                )
                ret, errors, rc = call_to_json(detail_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 200)
                self.assertTrue('pk' in ret)
                self.assertEqual(ret['pk'], sreg_pk)

                self.assertTrue('hwadapter_set' in ret)
                self.assertEqual(1, len(ret['hwadapter_set']))
                self.assertEqual(hw_pk, ret['hwadapter_set'][0]['pk'])
Esempio n. 22
0
            def create_vlan():
                command = [EXEC, DispatchVlan.dtype, 'create']
                for add_arg, extract_arg, test_f in DispatchVlan.create_args:
                    command.append(test_method_to_params(test_f()))

                vlan_ret, vlan_errors, vlan_rc = call_to_json(
                    ' '.join(command))

                if vlan_errors:
                    self.fail(vlan_errors)

                self.assertEqual(0, vlan_rc)

                # Make sure the SREG was created correctly
                self.assertTrue('http_status' in vlan_ret)
                self.assertEqual(vlan_ret['http_status'], 201)
                self.assertTrue('pk' in vlan_ret)
                return vlan_ret['pk']
Esempio n. 23
0
            def create_vlan():
                command = [EXEC, DispatchVlan.dtype, 'create']
                for add_arg, extract_arg, test_f in DispatchVlan.create_args:
                    command.append(test_method_to_params(test_f()))

                vlan_ret, vlan_errors, vlan_rc = call_to_json(
                    ' '.join(command)
                )

                if vlan_errors:
                    self.fail(vlan_errors)

                self.assertEqual(0, vlan_rc)

                # Make sure the SREG was created correctly
                self.assertTrue('http_status' in vlan_ret)
                self.assertEqual(vlan_ret['http_status'], 201)
                self.assertTrue('pk' in vlan_ret)
                return vlan_ret['pk']
Esempio n. 24
0
        def place_holder(self):
            # Create the object
            expected_status, command = commands[0]
            ret, errors, rc = call_to_json(self.modify_command(command))

            if errors:
                self.fail(errors)

            self.assertEqual(0, rc)

            self.assertTrue('http_status' in ret)
            self.assertEqual(ret['http_status'], expected_status)
            self.assertTrue('pk' in ret)
            obj_pk = ret['pk']

            # Look up the object
            detail_command = _("{0} {1} detail --pk {2}".format(
                EXEC, dispatch.dtype, obj_pk)
            )
            ret, errors, rc = call_to_json(detail_command)
            if errors:
                self.fail(errors)
            self.assertEqual(0, rc)

            self.assertTrue('http_status' in ret)
            self.assertEqual(ret['http_status'], 200)
            self.assertTrue('pk' in ret)
            self.assertEqual(ret['pk'], obj_pk)

            # The Update call
            expected_status, command = commands[1]
            command = "{0} --pk {1}".format(
                self.modify_command(command), obj_pk
            )
            ret, errors, rc = call_to_json(command)
            self.assertEqual(0, rc)

            if errors:
                self.fail(errors)

            self.assertTrue('http_status' in ret)
            self.assertEqual(ret['http_status'], expected_status)

            # Look up the object using the calculated detail command
            ret, errors, rc = call_to_json(detail_command)
            if errors:
                self.fail(errors)
            self.assertEqual(0, rc)

            self.assertTrue('http_status' in ret)
            self.assertEqual(ret['http_status'], 200)
            self.assertTrue('pk' in ret)
            self.assertEqual(ret['pk'], obj_pk)

            # Make sure an update doesn't require all the fields to be
            # specified
            blank_update_command = _("{0} {1} update --pk {2}".format(
                EXEC, dispatch.dtype, obj_pk)
            )
            ret, errors, rc = call_to_json(blank_update_command)
            if errors:
                self.fail(errors)
            self.assertEqual(0, rc)
            self.assertTrue('http_status' in ret)
            self.assertEqual(ret['http_status'], 202)

            # Delete the object
            delete_command = _("{0} {1} delete --pk {2}".format(
                EXEC, dispatch.dtype, obj_pk)
            )
            ret, errors, rc = call_to_json(delete_command)
            if errors:
                self.fail(errors)
            self.assertEqual(0, rc)
            self.assertTrue('http_status' in ret)
            self.assertEqual(ret['http_status'], 204)

            # Detail the object (expect a 404)
            ret, errors, rc = call_to_json(detail_command)
            if errors:
                self.fail(errors)
            self.assertEqual(1, rc)

            self.assertTrue('http_status' in ret)
            self.assertEqual(ret['http_status'], 404)
            self.assertFalse('pk' in ret)
Esempio n. 25
0
        def test_HW_and_SREG(self):
            # Create the SREG
            command = [EXEC, DispatchSREG.dtype, 'create']
            for add_arg, extract_arg, test_method in DispatchSREG.create_args:
                command.append(test_method_to_params(test_method()))

            sreg_ret, sreg_errors, sreg_rc = call_to_json(' '.join(command))

            if sreg_errors:
                self.fail(sreg_errors)

            self.assertEqual(0, sreg_rc)

            # Make sure the SREG was created correctly
            self.assertTrue('http_status' in sreg_ret)
            self.assertEqual(sreg_ret['http_status'], 201)
            self.assertTrue('pk' in sreg_ret)
            sreg_pk = sreg_ret['pk']

            # Create a HW
            command = [EXEC, DispatchHW.dtype, 'create']
            for add_arg, extract_arg, test_method in DispatchHW.create_args:
                command.append(test_method_to_params(test_method()))
            command_str = ' '.join(command)
            # lol, we are jinja2. evaluate our placeholder
            command_str = command_str.replace('{{ sreg_pk }}', str(sreg_pk))
            hw_ret, hw_errors, hw_rc = call_to_json(command_str)

            if hw_errors:
                self.fail(hw_errors)

            self.assertEqual(0, hw_rc)
            self.assertTrue('http_status' in hw_ret)
            self.assertEqual(hw_ret['http_status'], 201)
            self.assertTrue('pk' in hw_ret)
            hw_pk = hw_ret['pk']

            # Detail the hw and make sure we get the correct results
            def hw_detail():
                # Use a closure to keep outer context more clean
                detail_command = _("{0} {1} detail --pk {2}".format(
                    EXEC, DispatchHW.dtype, hw_pk)
                )
                ret, errors, rc = call_to_json(detail_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 200)
                self.assertTrue('pk' in ret)
                self.assertEqual(ret['pk'], hw_pk)

            # Detail the sreg and make sure we see the hw we created
            def detail_sreg_1():
                detail_command = _("{0} {1} detail --pk {2}".format(
                    EXEC, DispatchSREG.dtype, sreg_pk)
                )
                ret, errors, rc = call_to_json(detail_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 200)
                self.assertTrue('pk' in ret)
                self.assertEqual(ret['pk'], sreg_pk)

                self.assertTrue('hwadapter_set' in ret)
                self.assertEqual(1, len(ret['hwadapter_set']))
                self.assertEqual(hw_pk, ret['hwadapter_set'][0]['pk'])

            detail_sreg_1()

            def delete_hw():
                # Create a HW
                command = [EXEC, DispatchHW.dtype, 'create']
                for add_arg, extract_arg, tm in DispatchHW.create_args:
                    command.append(test_method_to_params(tm()))
                command_str = ' '.join(command)
                # lol, we are jinja2. evaluate our placeholder
                command_str = command_str.replace(
                    '{{ sreg_pk }}', str(sreg_pk))
                local_ret, local_errors, local_rc = call_to_json(command_str)

                if local_errors:
                    self.fail(local_errors)

                self.assertTrue('http_status' in local_ret)
                self.assertEqual(local_ret['http_status'], 201)
                self.assertTrue('pk' in local_ret)
                local_pk = local_ret['pk']

                delete_command = _("{0} {1} delete --pk {2}".format(
                    EXEC, DispatchHW.dtype, local_pk)
                )
                ret, errors, rc = call_to_json(delete_command)

                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)

                detail_command = _("{0} {1} detail --pk {2}".format(
                    EXEC, DispatchHW.dtype, local_pk)
                )
                ret, errors, rc = call_to_json(detail_command)

                if errors:
                    self.fail(errors)

                self.assertEqual(1, rc)

                self.assertTrue('http_status' in ret)
                self.assertEqual(ret['http_status'], 404)
                self.assertTrue('pk' not in ret)

            delete_hw()

            def delete_sreg_causing_hw_delete():
                delete_command = _("{0} {1} delete --pk {2}".format(
                    EXEC, DispatchSREG.dtype, sreg_pk)
                )
                ret, errors, rc = call_to_json(delete_command)
                if errors:
                    self.fail(errors)
                self.assertEqual(0, rc)

                # Make sure the SREG getting deleted caused a cascade delete
                detail_command = _("{0} {1} detail --pk {2}".format(
                    EXEC, DispatchHW.dtype, hw_pk)
                )
                local_ret, local_errors, local_rc = call_to_json(
                    detail_command)

                if local_errors:
                    self.fail(local_errors)

                self.assertEqual(1, local_rc)

                self.assertTrue('http_status' in local_ret)
                self.assertEqual(local_ret['http_status'], 404)
                self.assertTrue('pk' not in local_ret)

            delete_sreg_causing_hw_delete()