Пример #1
0
    def build_testcases(dispatch):
        commands = []
        command = [EXEC, dispatch.dtype, 'create']
        for add_arg, extract_arg, test_method in dispatch.create_args:
            command.append(test_method_to_params(test_method()))
        commands.append((201, ' '.join(command)))

        command = [EXEC, dispatch.dtype, 'update']
        for add_arg, extract_arg, test_method in dispatch.update_args:
            command.append(test_method_to_params(test_method()))
        commands.append((202, ' '.join(command)))

        return build_testcase(dispatch, commands)
Пример #2
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']
Пример #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']
Пример #4
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']
Пример #5
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']
Пример #6
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']
Пример #7
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']
Пример #8
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']
Пример #9
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']
Пример #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)
Пример #11
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()