def doit_wrapper(cfg, printflg=False):
    message = ""
    status = 3
    test_id = "TC10140"
    tims_dict = {test_id: ["US78110", message, status]}
    print "%s: BRB - Dual VMR - Redirect request from All VMR to a VMR and from Specific " \
          "VMR to a VMR with different copy type.." % (test_id)

    try:
        # announce
        # abspath = os.path.abspath(__file__)
        scriptName = os.path.basename(__file__)
        (test, ext) = os.path.splitext(scriptName)
        print "Starting test " + test

        if "no_brb" in cfg["test-flags"]:
            message = "Testcase Skipped: Skipping the testcase since no_brb flag is enabled."
            print message
            tims_dict = update_tims_data(tims_dict, 2, message, [test_id])
            return tims_dict

        # Initialize the Variables
        timeout = 2
        serviceIdlist = []

        # set values based on config
        cmdc_hosts = [cfg['cmdc']['host']]
        pps_hosts = [cfg['pps']['host']]
        upm_hosts = [cfg['upm']['host']]
        cmdc_port = cfg['cmdc']['port']
        pps_port = cfg['pps']['port']
        catalogueId = cfg['catalogueId']
        protocol = cfg['protocol']
        region = cfg['region']

        # Handle if the there are less channels than the threshold.
        threshold_channels = 17
        channelfilter1 = []
        for channels in cfg['test_channels'].keys():
            if channels.startswith("GenericCh"):
                channelfilter1.append(channels)
        if len(channelfilter1) < threshold_channels:
            message = "Skipping this TC since number of channels are less than 17."
            print message
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
            return tims_dict

        # Hardcoded the channel due to UUID channel issue while routing and recording.
        route_channel = '5b89b327-920f-402c-900d-1fb1e1784310'  #UUID equivalet of cfg['test_channels']['GenericCh1']['ServiceId']
        testchannel1 = cfg['test_channels']['GenericCh1']['ServiceId']
        testchannel2 = cfg['test_channels']['GenericCh2']['ServiceId']

        serviceIdlist.append(unicode(testchannel1))
        serviceIdlist.append(unicode(testchannel2))

        prefix = cfg['basic_feature']['household_prefix']
        fetch_bookingcatalog_delay = cfg['pps']['fetch_bookingCatalog_delay']
        recordingstatecheck_timedelay = cfg['pps']['booked_to_recording_delay']
        householdid1 = prefix + '1'
        householdid2 = prefix + '2'
        householdid3 = prefix + '3'
        householdid4 = prefix + '4'
        householdid_list = [
            householdid1, householdid2, householdid3, householdid4
        ]
        hostlist = list(itertools.product(cmdc_hosts, pps_hosts, upm_hosts))
        recording_delay = 180

        source_region = cfg["recorderRegion"]
        srt_content_reset = [[source_region, "*", source_region, "NoChange"]]
        common_copy = "Common"
        unique_copy = "Unique"
        dest_region = cfg["recorderRegion2"]
        copy_type = unique_copy
        ingest_delay = 120
        vmr = cfg['vmr']
        aws_vmr = cfg['vmr2']
        region_index = 5

        srt_content = [["*", "*", dest_region, common_copy],
                       [source_region, testchannel2, dest_region, unique_copy]]

        # Do PPS Booking
        pps_headers = {
            'Content-Type': 'application/json',
            'Source-Type': 'WEB',
            'Source-ID': '127.0.0.1',
        }

        ###########################  USER DEFINED POST TIME IN UTC ############################
        start_delay = 5
        timeslotinminutes = cfg["test_channels"]["longProgramLength"]
        ingestion_time = get_utc_time_after_n_minutes(start_delay, True)
        start_time = datetime.datetime.strptime(ingestion_time,
                                                '%Y-%m-%dT%H:%M:%S')
        post_time = calendar.timegm(start_time.timetuple()) + 0.0001
        #######################################################################################

        print "### STEP1: Ingest an event on channel 1 & channel 2 with 5 minutes duration " \
              "and 5 minues post time. ###\n"
        ci_host = cfg['ci']['host']
        ci_port = cfg['ci']['port']
        ingest_minimum_delay = cfg['ci']['ingest_minimum_delay']
        ingest_delay_factor_per_minute = cfg['ci'][
            'ingest_delay_factor_per_minute']

        eventtitle1 = "TC10140" + str(random.randint(1, 499))

        channel1 = ChannelLineup(BoundaryInMinutes=0)
        channel1.add_to_lineup(serviceId=testchannel1,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=1,
                               programIDPrefix=eventtitle1)
        channel1.postXmlData(ci_host, ci_port, startTime=post_time)
        channel1.writeXmlFiles(startTime=post_time)

        print "channel1 : ", channel1

        channel2 = ChannelLineup(BoundaryInMinutes=0)
        channel2.add_to_lineup(serviceId=testchannel2,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=1,
                               programIDPrefix=eventtitle1)
        channel2.postXmlData(ci_host, ci_port, startTime=post_time)
        channel2.writeXmlFiles(startTime=post_time)

        print "channel2 : ", channel2

        print "Wait time for the catalog ingest to " \
              "get synced with the CI Host in seconds: " + str(ingest_delay)
        time.sleep(ingest_delay)

    except:
        message = "Testcase Failed: Error Occurred in Configuration " + PrintException(
            True)
        print message
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
        return tims_dict

    for (cmdc_host, pps_host, upm_host) in hostlist:
        try:
            print "### STEP2 : Ensure four household present in the system pointing to RR1 " \
                  "recording region. ###\n"
            for household in householdid_list:
                hh_region = get_household_region(cfg, upm_host, household,
                                                 timeout)
                assert hh_region == source_region, "Testcase Fail : Household %s not in the " \
                                                   "source region %s" % (household, source_region)

            print "### STEP3:  Modify the SRT in such a way, ###\n"
            print "### STEP 3.1. To record the contents on hh 1 (any region) and from any " \
                  "channel with common copy type in RR2 recording region. ###\n"
            print "### STEP 3.2. To record the contents on hh 2 (RR1 region) and from " \
                  "channel 2 with unique copy type in RR2 recording region.###\n"

            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content)

            # Cleaning up the household
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host,
                                  householdid, pps_headers, timeout)

            gridservicelistresponse = fetch_gridRequest(catalogueId, protocol, cmdc_host, \
                                                        cmdc_port, serviceIdlist, region, timeout,
                                                        printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(gridservicelistresponse, \
                                                           eventtitle1, ['title'])
            print "ContentID dictionary from the Grid Response\n" + str(
                contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable " \
                                       "to Form ContentId dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (len(contentId_list) > 0), "Testcase Failed: Unable " \
                                              "to form ContentId list from ContentId dictionary"
            print "len(contentId_list) : ", len(contentId_list)

            print "### STEP4. Perform booking on all four households for the ingested contents.##\n"
            print "## STEP 4.1. Perform the booking on channel 1 on hh 1##"
            content_ev1 = contentId_list[0][0]
            ev1_broadcast_start_time = contentId_list[0][1][0]
            payload_ev1 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev1)

            result = do_PPSbooking(pps_port, protocol, pps_host, householdid_list[0], \
                                   pps_headers, payload_ev1, content_ev1, timeout, printflg)
            if result != "PASS":
                message = "Testcase Failed:Unable to do pps booking of content ID " \
                          + str(content_ev1) + " in household " + str(householdid_list[0])
                print message
                tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

            print "## STEP 4.2. Perform the booking on channel 2 on hh 2##"
            content_ev2 = contentId_list[0][0]
            payload_ev2 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev2)

            result = do_PPSbooking(pps_port, protocol, pps_host, householdid_list[1], \
                                   pps_headers, payload_ev2, content_ev2, timeout, printflg)
            if result != "PASS":
                message = "Testcase Failed:Unable to do pps booking of content ID " \
                          + str(content_ev1) + " in household " + str(householdid_list[1])
                print message
                tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

            time.sleep(fetch_bookingcatalog_delay)
            print "About to start the event 1 booking\n"
            # Getting Catalog Response for the Booked Catalog
            catalogresult, catalogresponse = verify_booking(
                pps_port, protocol, pps_host, householdid_list[0], content_ev1,
                timeout)
            print "Booking response of Event 1:", catalogresult
            assert catalogresult == "PASS", "TestCase  Failed : Content ID " + str(content_ev1) \
                                            + " in household " + str(householdid) \
                                            + " is not in the BOOKED state"

            catalogresult, catalogresponse = verify_booking(
                pps_port, protocol, pps_host, householdid_list[1], content_ev2,
                timeout)
            print "Booking response of Event 2 :\n", catalogresult
            assert catalogresult == "PASS", "TestCase  Failed : Content ID " \
                                            + str(content_ev2) + " in household " \
                                            + str(householdid) + " is not in the BOOKED state"

            print "### STEP5. Wait for the program to start its recording on all four " \
                  "households.####\n"

            broadcasting_starttime = get_timedifference(
                ev1_broadcast_start_time, printflg)
            recordingstatechage = recordingstatecheck_timedelay + broadcasting_starttime
            print "Script will wait for ", recordingstatechage," seconds to check the event " \
                                                               "recording state"
            time.sleep(recordingstatechage)
            print "Waiting additional %s seconds to workaround the " \
                  "state change issue." % (recording_delay)
            time.sleep(recording_delay)

            recrding_res1, recrding_resp1 = verify_recording_state(
                pps_port, protocol, pps_host, householdid_list[0], content_ev1,
                timeout)
            if recrding_res1 != "PASS":
                message = "Testcase Failed: Content ID {0} in household {1} is " \
                          "not in the RECORDING state".format(content_ev1, householdid)
                assert False, message

            recrding_res2, recrding_resp2 = verify_recording_state(
                pps_port, protocol, pps_host, householdid_list[1], content_ev2,
                timeout)
            if recrding_res2 != "PASS":
                message = "Testcase Failed: Content ID {0} in household {1} is not in the " \
                          "RECORDING state".format(content_ev2, householdid)
                assert False, message

            print "### STEP 6. Confirm from VMR API response that recorded contents.###\n"

            print "## STEP 6.1. Content from channel 1 recorded on hh1 with Common copy type " \
                  "in RR2 recording region.##"
            cfg['vmr'] = vmr
            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev1],
                                                       householdid_list[0],
                                                       timeout)
            print "Playback URI list :", playbackuri_list
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            print "ContentId list :", contentidlist
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            riodev_recording_hh1 = json.loads(vmr_response_1.content)[0]
            region_hh1 = riodev_recording_hh1['A8UpdateURL'].split(
                '/')[region_index]
            hh1_copy_type = riodev_recording_hh1["CopyType"]

            print "riodev_recording_hh1 : ", riodev_recording_hh1

            print "region_hh1 : ", region_hh1

            assert hh1_copy_type == common_copy, \
                "Testcase Failed: Content %s are not in expected copy " \
                "type %s in household 1 " % (content_ev1, copy_type)

            assert region_hh1 == dest_region, \
                "Testcase Failed: Content %s are not in expected region " \
                " %s in household 1 " % (content_ev1, dest_region)

            print "## STEP6.2. Content from channel 2 recorded on hh2 with Unique copy type " \
                  "in RR2 recording region.##"

            cfg['vmr'] = aws_vmr
            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev1],
                                                       householdid_list[2:4],
                                                       timeout)
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[0], timeout)
            riodev_recording_hh2 = json.loads(vmr_response_2.content)[0]
            region_hh2 = riodev_recording_hh2['A8UpdateURL'].split(
                '/')[region_index]
            hh2_copy_type = riodev_recording_hh2["CopyType"]

            print "riodev_recording_hh2 : ", riodev_recording_hh2

            print "region_hh2 : ", region_hh2

            assert hh2_copy_type == unique_copy, \
                "Testcase Failed: Content %s are not in expected copy " \
                "type %s in household 2." % (content_ev1, unique_copy)

            assert region_hh2 == dest_region, \
                "Testcase Failed: Content %s are not in expected region " \
                " %s in household 2." % (content_ev1, dest_region)

            message = "TestCase Passed : SRT is working as expected."
            tims_dict = update_tims_data(tims_dict, 0, message, [test_id])

        except AssertionError as ae:
            message = str(ae)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        except Exception as e:
            message = str(e)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        finally:
            print "### STEP7. Cleanup the households and srt table. ###\n"
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host,
                                  householdid, pps_headers, timeout)
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content_reset)
            print message
            return tims_dict
Example #2
0
def doit_wrapper(cfg, printflg=False):
    message = ""
    status = 3
    test_id = "TC10122"
    tims_dict = {test_id: ["US78110", message, status]}
    print "%s: BRB - Dual VMR - Redirect recording before scheduling from VMR1 to VMR2 based on " \
          "multiple channels and single channel with different copy type" % (test_id)

    try:
        # announce
        # abspath = os.path.abspath(__file__)
        scriptName = os.path.basename(__file__)
        (test, ext) = os.path.splitext(scriptName)
        print "Starting test " + test

        if "no_brb" in cfg["test-flags"]:
            message = "Testcase Skipped: Skipping the testcase since no_brb flag is enabled."
            print message
            tims_dict = update_tims_data(tims_dict, 2, message, [test_id])
            return tims_dict

        # Initialize the Variables
        timeout = 2
        serviceIdlist = []

        # set values based on config
        cmdc_hosts = [cfg['cmdc']['host']]
        pps_hosts = [cfg['pps']['host']]
        upm_hosts = [cfg['upm']['host']]
        upm_port = cfg['upm']['port']
        cmdc_port = cfg['cmdc']['port']
        pps_port = cfg['pps']['port']
        catalogueId = cfg['catalogueId']
        protocol = cfg['protocol']
        region = cfg['region']

        ch1 = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "channels"][0]
        ch2 = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "channels"][1]

        testchannel1 = cfg['test_channels'][ch1]['ServiceId']
        testchannel1_uuid = cfg['test_channels'][ch1]['UUID']
        testchannel2 = cfg['test_channels'][ch2]['ServiceId']

        serviceIdlist.append(unicode(testchannel1))
        serviceIdlist.append(unicode(testchannel2))

        prefix = cfg['basic_feature']['household_prefix']
        fetch_bookingcatalog_delay = cfg['pps']['fetch_bookingCatalog_delay']
        recordingstatecheck_timedelay = cfg['pps']['booked_to_recording_delay']
        householdid1 = prefix + '1'
        householdid2 = prefix + '2'
        householdid3 = prefix + '3'
        householdid4 = prefix + '4'
        householdid_list = [
            householdid1, householdid2, householdid3, householdid4
        ]
        hostlist = list(itertools.product(cmdc_hosts, pps_hosts, upm_hosts))
        recording_delay = 180

        cmdcRegion = cfg['cmdcRegion']
        adZone = cfg['adZone']
        marketingTarget = cfg['marketingTarget']

        source_region = cfg["feature"]["brb"]["Recorderegions"]["v2pcVMR"][
            "name"]
        dest_region = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "name"]
        srt_content_reset = [[source_region, "*", source_region, "NoChange"]]
        common_copy = "COMMON"
        unique_copy = "UNIQUE"
        vmr = cfg["vmr"]["instances"]["v2pcVMR"]
        aws_vmr = cfg["vmr"]["instances"]["standaloneVMR"]
        print "VMR : ", vmr
        print "AWS_VMR :", aws_vmr
        region_index = 5

        srt_content = [[
            source_region,
            str(testchannel1_uuid), dest_region, unique_copy
        ], [source_region, '*', dest_region, common_copy]]

        # Do PPS Booking
        pps_headers = {
            'Content-Type': 'application/json',
            'Source-Type': 'WEB',
            'Source-ID': '127.0.0.1',
        }

        # ##########################  USER DEFINED POST TIME IN UTC ############################
        start_delay = 5
        timeslotinminutes = cfg["test_channels"]["longProgramLength"]
        ingestion_time = get_utc_time_after_n_minutes(start_delay, True)
        start_time = datetime.datetime.strptime(ingestion_time,
                                                '%Y-%m-%dT%H:%M:%S')
        post_time = calendar.timegm(start_time.timetuple()) + 0.0001
        #######################################################################################

        print "### STEP1: Ingest an event on channel 1  with 5 minutes duration and 5 minutes " \
              "post time. ###\n"
        ci_host = cfg['ci']['host']
        ci_port = cfg['ci']['port']
        ingest_minimum_delay = cfg['ci']['ingest_minimum_delay']
        ingest_delay_factor_per_minute = cfg['ci'][
            'ingest_delay_factor_per_minute']

        eventtitle1 = "TC10122" + str(random.randint(1, 499))
        channel1 = ChannelLineup(BoundaryInMinutes=0)
        channel1.add_to_lineup(serviceId=testchannel1,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=1,
                               programIDPrefix=eventtitle1)
        channel1.postXmlData(ci_host, ci_port, startTime=post_time)
        channel1.writeXmlFiles(startTime=post_time)

        print "channel1 : ", channel1

        channel2 = ChannelLineup(BoundaryInMinutes=0)
        channel2.add_to_lineup(serviceId=testchannel2,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=1,
                               programIDPrefix=eventtitle1)
        channel2.postXmlData(ci_host, ci_port, startTime=post_time)
        channel2.writeXmlFiles(startTime=post_time)

        print "channel2 : ", channel2

        length = channel1.getTotalLength() + channel2.getTotalLength()
        sleep_channel = ingest_minimum_delay + length * ingest_delay_factor_per_minute

        print "Wait time for the catalog ingest to " \
              "get synced with the CI Host in seconds: " + str(sleep_channel)
        time.sleep(sleep_channel)

    except:
        message = "Testcase Failed: Error Occurred in Configuration " + PrintException(
            True)
        print message
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
        return tims_dict

    for (cmdc_host, pps_host, upm_host) in hostlist:
        try:

            print "### STEP2 : Ensure four household present in the system pointing to" \
                  " RR1 recording region. ###\n"
            for household in householdid_list:
                hh_region = get_household_region(cfg, upm_host, household,
                                                 timeout)
                assert hh_region == source_region, "Testcase Fail : Household %s not in the " \
                                                   "source region %s" % (household, source_region)

            print "### STEP3:  Modify the SRT in such a way, ###\n"
            print "### STEP 3.1. To record the contents of hh 1, hh2(RR1 region) and from " \
                  "channel 1 with Unique copy type in RR2 recording region. ###\n"
            print "### STEP 3.2. To record the contents of hh 3, hh4(RR1 region) and from " \
                  "all channels with common copy type in RR2 recording region.###\n"

            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content)

            # Cleaning up the household
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host,
                                  householdid, pps_headers, timeout)

            gridservicelistresponse = fetch_gridRequest(
                catalogueId, protocol, cmdc_host, cmdc_port, [
                    unicode(testchannel1),
                ], region, timeout, printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(
                gridservicelistresponse, eventtitle1, ['title'])
            print "ContentID dictionary from the Grid Response\n" + str(
                contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable " \
                                       "to Form ContentId dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (len(contentId_list) > 0), "Testcase Failed: Unable " \
                                              "to form ContentId list from ContentId dictionary"
            print "len(contentId_list) : ", len(contentId_list)

            content_ev1 = contentId_list[0][0]
            ev1_broadcast_start_time = contentId_list[0][1][0]

            gridservicelistresponse = fetch_gridRequest(
                catalogueId, protocol, cmdc_host, cmdc_port, [
                    unicode(testchannel2),
                ], region, timeout, printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(
                gridservicelistresponse, eventtitle1, ['title'])
            print "ContentID dictionary from the Grid Response\n" + str(
                contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable " \
                                       "to Form ContentId dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (len(contentId_list) > 0), "Testcase Failed: Unable " \
                                              "to form ContentId list from ContentId dictionary"
            print "len(contentId_list) : ", len(contentId_list)

            content_ev2 = contentId_list[0][0]

            print "### STEP4. Perform booking on all four households for the ingested contents###\n"
            print "## STEP 4.1. Perform the booking on channel 1 on hh 1 & hh2.##"
            payload_ev1 = """{
                                "scheduleInstanceId" : "%s",
                                "checkConflicts" : true,
                                "pvr":"nPVR"
                                }""" % (content_ev1)

            for householdid in householdid_list[:2]:
                result = do_PPSbooking(pps_port, protocol, pps_host, householdid, \
                                       pps_headers, payload_ev1, content_ev1, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev1) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            print "## STEP 4.2. Perform the booking on channel 2 on hh 3 & hh4.##"
            payload_ev2 = """{
                                "scheduleInstanceId" : "%s",
                                "checkConflicts" : true,
                                "pvr":"nPVR"
                                }""" % (content_ev2)

            for householdid in householdid_list[2:4]:
                result = do_PPSbooking(pps_port, protocol, pps_host, householdid, \
                                       pps_headers, payload_ev2, content_ev2, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev1) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            time.sleep(fetch_bookingcatalog_delay)
            print "About to start the event 1 booking\n"
            # Getting Catalog Response for the Booked Catalog
            for householdid in householdid_list[:2]:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                print "Booking response of Event 1:", catalogresult
                assert catalogresult == "PASS", "TestCase  Failed : Content ID " + str(content_ev1) \
                                                + " in household " + str(householdid) \
                                                + " is not in the BOOKED state"

            for householdid in householdid_list[2:4]:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)
                print "Booking response of Event 2 :\n", catalogresult
                assert catalogresult == "PASS", "TestCase  Failed : Content ID " \
                                                + str(content_ev2) + " in household " \
                                                + str(householdid) + " is not in the BOOKED state"

            print "### STEP5.Wait for the program to start its recording on all four " \
                  "households.####\n"

            broadcasting_starttime = get_timedifference(
                ev1_broadcast_start_time, printflg)
            recordingstatechage = recordingstatecheck_timedelay + broadcasting_starttime
            print "Script will wait for ", recordingstatechage," seconds to check the event " \
                                                               "recording state"
            time.sleep(recordingstatechage)
            print "Waiting additional %s seconds to workaround the " \
                  "state change issue." % (recording_delay)
            time.sleep(recording_delay)

            for householdid in householdid_list[:2]:
                recrding_res1, recrding_resp1 = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                if recrding_res1 != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is " \
                              "not in the RECORDING state".format(content_ev1, householdid)
                    assert False, message

            for householdid in householdid_list[2:4]:
                recrding_res2, recrding_resp2 = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)
                if recrding_res2 != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is not in the " \
                              "RECORDING state".format(content_ev2, householdid)
                    assert False, message

            print "### STEP 6. Confirm from VMR API response that recorded contents are as per " \
                  "the rule set in SRT. ###\n"

            cfg['vmr']['host'] = aws_vmr
            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev1],
                                                       householdid_list[:2],
                                                       timeout)
            print "Playback URI list :", playbackuri_list
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            print "ContentId list :", contentidlist
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            assert vmr_response_1 and vmr_response_1.content != 'null', \
                "Testcase Failed : Unable to get the VMR response for contentId " \
                "%s" % contentidlist[0]
            assert vmr_response_2 and vmr_response_2.content != 'null', \
                "Testcase Failed : Unable to get the VMR response for contentId " \
                "%s" % contentidlist[1]
            riodev_recording_hh1 = json.loads(vmr_response_1.content)[0]
            riodev_recording_hh2 = json.loads(vmr_response_2.content)[0]
            region_hh1 = riodev_recording_hh1['A8UpdateURL'].split(
                '/')[region_index]
            region_hh2 = riodev_recording_hh2['A8UpdateURL'].split(
                '/')[region_index]
            hh1_copy_type = riodev_recording_hh1["CopyType"]
            hh2_copy_type = riodev_recording_hh2["CopyType"]

            print "riodev_recording_hh1 : ", riodev_recording_hh1
            print "riodev_recording_hh2 : ", riodev_recording_hh2

            print "region_hh1 : ", region_hh1
            print "region_hh2 : ", region_hh2

            assert hh1_copy_type == hh2_copy_type == unique_copy, \
                "Testcase Failed: Content %s are not in expected copy " \
                "type %s in household 1 & household 2." % (content_ev1, unique_copy)

            assert region_hh1 == region_hh2 == dest_region, \
                "Testcase Failed: Content %s are not in expected region " \
                " %s in household 1 & household 2." % (content_ev1, dest_region)

            print "## STEP6.2. Content from channel 2 booked on hh3 & hh4 with common copy " \
                  "type in RR2 recording region. ##"

            cfg['vmr']['host'] = aws_vmr
            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev2],
                                                       householdid_list[2:4],
                                                       timeout)
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            vmr_response_3 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_4 = get_vmr_response(cfg, contentidlist[1], timeout)
            assert vmr_response_3 and vmr_response_3.content != 'null', \
                "Testcase Failed : Unable to get the VMR response for contentId " \
                "%s" % contentidlist[0]
            assert vmr_response_4 and vmr_response_4.content != 'null', \
                "Testcase Failed : Unable to get the VMR response for contentId " \
                "%s" % contentidlist[1]
            riodev_recording_hh3 = json.loads(vmr_response_3.content)[0]
            riodev_recording_hh4 = json.loads(vmr_response_4.content)[0]
            region_hh3 = riodev_recording_hh3['A8UpdateURL'].split(
                '/')[region_index]
            region_hh4 = riodev_recording_hh4['A8UpdateURL'].split(
                '/')[region_index]
            hh3_copy_type = riodev_recording_hh3["CopyType"]
            hh4_copy_type = riodev_recording_hh4["CopyType"]

            print "riodev_recording_hh3 : ", riodev_recording_hh3
            print "riodev_recording_hh4 : ", riodev_recording_hh4

            print "region_hh3 : ", region_hh3
            print "region_hh4 : ", region_hh4

            assert hh3_copy_type == hh4_copy_type == common_copy, \
                "Testcase Failed: Content %s are not in expected copy " \
                "type %s in household 3." % (content_ev1, common_copy)

            assert region_hh3 == dest_region and region_hh4 == dest_region, \
                "Testcase Failed: Content %s are not in expected region " \
                " %s in household 3." % (content_ev1, dest_region)

            message = "TestCase Passed : SRT is working as expected."
            tims_dict = update_tims_data(tims_dict, 0, message, [test_id])

        except AssertionError as ae:
            message = str(ae)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        except Exception as e:
            message = str(e)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        finally:
            print "### STEP7. Cleanup the households and srt table. ###\n"
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host,
                                  householdid, pps_headers, timeout)
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content_reset)
            print message
            return tims_dict
Example #3
0
def doit_wrapper(cfg, printflg=False):
    message = ""
    status = 3
    test_id = "TC10131"
    tims_dict = {test_id: ["US80587", message, status]}
    print "%s: BRB - Dual VMR - Redirect recording before scheduling from VMR1 to VMR2 for all channels with unique copy type." % (
        test_id)

    try:
        # announce
        # abspath = os.path.abspath(__file__)
        scriptName = os.path.basename(__file__)
        (test, ext) = os.path.splitext(scriptName)
        print "Starting test " + test

        if "no_brb" in cfg["test-flags"]:
            message = "Testcase Skipped: Skipping the testcases since no_brb flag is enabled."
            print message
            tims_dict = update_tims_data(tims_dict, 2, message, [test_id])
            return tims_dict

        # Initialize the Variables
        timeout = 2
        serviceIdlist = []

        # set values based on config
        cmdc_hosts = [cfg['cmdc']['host']]
        pps_hosts = [cfg['pps']['host']]
        cmdc_port = cfg['cmdc']['port']
        pps_port = cfg['pps']['port']
        catalogueId = cfg['catalogueId']
        protocol = cfg['protocol']
        region = cfg['region']

        ch1 = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "channels"][0]
        ch2 = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "channels"][1]

        testchannel1 = cfg['test_channels'][ch1]['ServiceId']
        testchannel1_uuid = cfg['test_channels'][ch1]['UUID']
        testchannel2 = cfg['test_channels'][ch2]['ServiceId']

        serviceIdlist.append(unicode(testchannel1))
        serviceIdlist.append(unicode(testchannel2))

        prefix = cfg['feature']['household_prefix']
        fetch_bookingcatalog_delay = cfg['pps']['fetch_bookingCatalog_delay']
        recordingstatecheck_timedelay = cfg['pps']['booked_to_recording_delay']
        householdid1 = prefix + '1'
        householdid2 = prefix + '2'
        householdid3 = prefix + '3'
        householdid4 = prefix + '4'
        householdid_list = [
            householdid1, householdid2, householdid3, householdid4
        ]
        hostlist = list(itertools.product(cmdc_hosts, pps_hosts))
        broadcasting_starttime = 0
        broadcasting_endtime = 0
        recording_delay = 60
        common_copy = "COMMON"
        unique_copy = "UNIQUE"
        source_region = cfg["feature"]["brb"]["Recorderegions"]["v2pcVMR"][
            "name"]
        dest_region = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "name"]
        v2pcVMR_host = cfg["vmr"]["instances"]["v2pcVMR"]
        standaloneVMR_host = cfg["vmr"]["instances"]["standaloneVMR"]
        default_copy_type = unique_copy
        ingest_delay = 120

        srt_content = [[source_region, "*", dest_region, "Unique"]]
        srt_content_reset = [[source_region, "*", source_region, "NoChange"]]

        # Do PPS Booking
        pps_headers = {
            'Content-Type': 'application/json',
            'Source-Type': 'WEB',
            'Source-ID': '127.0.0.1',
        }

        ###########################  USER DEFINED POST TIME IN UTC ############################
        start_delay = 5
        timeslotinminutes = cfg["test_channels"]["longProgramLength"]
        ingestion_time = get_utc_time_after_n_minutes(start_delay, True)
        start_time = datetime.datetime.strptime(ingestion_time,
                                                '%Y-%m-%dT%H:%M:%S')
        post_time = calendar.timegm(start_time.timetuple()) + 0.0001
        #######################################################################################

        print "### STEP1: Ingest an event of n minutes with the " \
              "posttime of n Minutes to the CI Host ######## \n \n"
        ci_host = cfg['ci']['host']
        ci_port = cfg['ci']['port']
        ingest_minimum_delay = cfg['ci']['ingest_minimum_delay']
        ingest_delay_factor_per_minute = cfg['ci'][
            'ingest_delay_factor_per_minute']

        eventtitle1 = "TC10131" + str(random.randint(1, 499))

        channel1 = ChannelLineup(BoundaryInMinutes=0)
        channel1.add_to_lineup(serviceId=testchannel1, \
                               timeSlotLengthMinutes=timeslotinminutes, timeSlotCount=1, \
                               programIDPrefix=eventtitle1)
        channel1.postXmlData(ci_host, ci_port, startTime=post_time)
        channel1.writeXmlFiles(startTime=post_time)

        print "channel1 : ", channel1

        channel2 = ChannelLineup(BoundaryInMinutes=0)
        channel2.add_to_lineup(serviceId=testchannel2, \
                               timeSlotLengthMinutes=timeslotinminutes, timeSlotCount=1, \
                               programIDPrefix=eventtitle1)
        channel2.postXmlData(ci_host, ci_port, startTime=post_time)
        channel2.writeXmlFiles(startTime=post_time)

        print "channel2 : ", channel2

        print "Wait time for the catalog ingest to " \
              "get synced with the CI Host in seconds: " + str(ingest_delay)
        time.sleep(ingest_delay)

    except:
        message = "Testcase Failed: Error Occurred in Configuration " + PrintException(
            True)
        print message
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
        return tims_dict

    for (cmdc_host, pps_host) in hostlist:
        try:

            print "### STEP2: Setting the SRT table. ###### \n \n"
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content)

            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, \
                                  pps_host, householdid, pps_headers, timeout)

            print "### STEP3: Fetching the grid response to " \
                  "collect the ingested content. ##### \n \n"
            gridservicelistresponse = fetch_gridRequest(catalogueId, protocol, cmdc_host, \
                                                        cmdc_port, [unicode(testchannel1),], region, timeout, printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(gridservicelistresponse, \
                                                           eventtitle1, ['title'])
            print "ContentID dictionary from the Grid Response\n" + str(
                contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable " \
                                       "to Form ContentId dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (len(contentId_list) > 0), "Testcase Failed: Unable " \
                                              "to form ContentId list from ContentId dictionary"
            print "len(contentId_list) : ", len(contentId_list)

            content_ev1 = contentId_list[0][0]


            gridservicelistresponse = fetch_gridRequest(catalogueId, protocol, cmdc_host, \
                                                        cmdc_port, [unicode(testchannel2),], region, timeout, printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(gridservicelistresponse, \
                                                           eventtitle1, ['title'])
            print "ContentID dictionary from the Grid Response\n" + str(
                contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable " \
                                       "to Form ContentId dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (len(contentId_list) > 0), "Testcase Failed: Unable " \
                                              "to form ContentId list from ContentId dictionary"
            print "len(contentId_list) : ", len(contentId_list)

            content_ev2 = contentId_list[0][0]

            payload_ev1 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev1)

            payload_ev2 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev2)

            print "About to start the event 1 booking\n\n"
            print "### STEP4: PPS event-1(on hh1, hh2), event-2(on hh3, hh4) " \
                  "booking respectively from channel 1 & channel 2 is being done. ##### \n \n"
            for householdid in householdid_list[:2]:
                result = do_PPSbooking(pps_port, protocol, pps_host, householdid, \
                                       pps_headers, payload_ev1, content_ev1, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev1) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            for householdid in householdid_list[2:4]:
                result = do_PPSbooking(pps_port, protocol, pps_host, householdid, \
                                       pps_headers, payload_ev2, content_ev2, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev2) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            print "### STEP5: Confirming that the households has the items " \
                  "in booked state. ##### \n \n"
            time.sleep(fetch_bookingcatalog_delay)
            # Getting Catalog Response for the Booked Catalog
            for householdid in householdid_list[:2]:
                catalogresult, catalogresponse = verify_booking(pps_port, protocol, \
                                                                pps_host, householdid, content_ev1, timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev1:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " + str(content_ev1) + " in household " \
                              + str(householdid) + " is not in the BOOKED state"
                    assert False, message

            for householdid in householdid_list[2:4]:
                catalogresult, catalogresponse = verify_booking(pps_port, \
                                                                protocol, pps_host, householdid, \
                                                                content_ev2, timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev2:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " \
                              + str(content_ev2) + " in household " + str(householdid) \
                              + " is not in the BOOKED state"
                    assert False, message

            broadcasting_starttime = timeDiff(broadcasting_starttime)
            recordingstatechage = recordingstatecheck_timedelay + broadcasting_starttime
            print "Script will wait for " + str(recordingstatechage / 60) \
                  + " minutes to check the event recording state"
            time.sleep(recordingstatechage)
            print "Waiting additional %s seconds to workaround the " \
                  "state change issue." % (recording_delay)
            time.sleep(recording_delay)
            time.sleep(recording_delay)

            print "### STEP6: Confirming that all households has the booked items " \
                  "in recording state. ##### \n \n"
            for householdid in householdid_list[:2]:
                recordingcatalogresult, recordingcatalogresponse = verify_recording_state(pps_port, \
                                                                                          protocol, pps_host,
                                                                                          householdid, content_ev1,
                                                                                          timeout)
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is " \
                              "not in the RECORDING state".format(content_ev1, householdid)
                    assert False, message

            for householdid in householdid_list[2:4]:
                recordingcatalogresult, recordingcatalogresponse = verify_recording_state(pps_port, \
                                                                                          protocol, pps_host,
                                                                                          householdid, \
                                                                                          content_ev2, timeout)
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is not in the " \
                              "RECORDING state".format(content_ev2, householdid)
                    assert False, message

            print "### STEP7: Confirming that all households, recording its content " \
                  "with expected copy type and in expected region. ##### \n \n"

            switch_vmr_host(cfg, standaloneVMR_host)
            playbackuri_list = get_content_playbackURI(pps_host, pps_port, \
                                                       protocol, [content_ev1], householdid_list[:2], timeout)
            print "Playback URI list :", playbackuri_list
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            print "ContentId list :", contentidlist
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            riodev_recording_hh1 = json.loads(vmr_response_1.content)[0]
            riodev_recording_hh2 = json.loads(vmr_response_2.content)[0]

            print "riodev_recording_hh1 : ", riodev_recording_hh1
            print "riodev_recording_hh2 : ", riodev_recording_hh2
            assert riodev_recording_hh1["CopyType"] == unique_copy and \
                   riodev_recording_hh2["CopyType"] == unique_copy and \
                   riodev_recording_hh1["A8UpdateURL"].split('/')[5] == dest_region and \
                   riodev_recording_hh2["A8UpdateURL"].split('/')[5] == dest_region, \
                "Testcase Failed: Content %s are not in expected copy " \
                "type %s in household 1 & household 2." % (content_ev1, unique_copy)

            playbackuri_list = get_content_playbackURI(pps_host, \
                                                       pps_port, protocol, \
                                                       [content_ev2], householdid_list[2:4], timeout)
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            riodev_recording_hh3 = json.loads(vmr_response_1.content)[0]
            riodev_recording_hh4 = json.loads(vmr_response_2.content)[0]
            print "riodev_recording_hh3 : ", riodev_recording_hh3
            print "riodev_recording_hh4 : ", riodev_recording_hh4
            assert riodev_recording_hh3["CopyType"] == default_copy_type and \
                   riodev_recording_hh4["CopyType"] == default_copy_type and \
                   riodev_recording_hh3["A8UpdateURL"].split('/')[5] == dest_region and \
                   riodev_recording_hh4["A8UpdateURL"].split('/')[5] == dest_region, \
                "Testcase Failed: Content %s are not in expected copy " \
                "type %s in household 3 & household 4." % (content_ev2, default_copy_type)

            message = "TestCase Passed : SRT is working as expected."
            tims_dict = update_tims_data(tims_dict, 0, message, [test_id])

        except AssertionError as ae:
            message = str(ae)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        except Exception as e:
            message = str(e)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        finally:
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host, \
                                  householdid, pps_headers, timeout)
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content_reset)
            print message
            return tims_dict
Example #4
0
def doit_wrapper(cfg, printflg=False):

    message = ""
    status = 3
    test_id = "TC9841"
    tims_dict = {test_id: ["US80599", message, status]}
    print "%s: Big Red Button - SRT with time based booking" % test_id

    try:
        # announce
        # abspath = os.path.abspath(__file__)
        scriptName = os.path.basename(__file__)
        (test, ext) = os.path.splitext(scriptName)
        print "Starting test " + test

        if "no_brb" in cfg["test-flags"]:
            message = "Testcase Skipped: Skipping the testcases since no_brb flag is enabled."
            print message
            tims_dict = update_tims_data(tims_dict, 2, message, [test_id])
            return tims_dict

        # Initialize the Variables
        timeout = 2
        serviceIdlist = []

        # set values based on config
        cmdc_hosts = [cfg['cmdc']['host']]
        pps_hosts = [cfg['pps']['host']]
        cmdc_port = cfg['cmdc']['port']
        pps_port = cfg['pps']['port']
        catalogueId = cfg['catalogueId']
        protocol = cfg['protocol']
        region = cfg['region']

        testchannel1 = cfg['test_channels']['GenericCh1']['ServiceId']
        serviceIdlist.append(unicode(testchannel1))

        prefix = cfg['feature']['household_prefix']
        bookingCatalog_delay = cfg['pps']['fetch_bookingCatalog_delay']
        recordingstatecheck_timedelay = cfg['pps']['booked_to_recording_delay']
        recording_to_recorded_delay = cfg['pps']['recording_to_recorded_delay']
        householdid1 = prefix + '1'
        householdid2 = prefix + '2'
        householdid3 = prefix + '3'
        householdid4 = prefix + '4'
        householdid_list = [
            householdid1, householdid2, householdid3, householdid4
        ]
        hostlist = list(itertools.product(cmdc_hosts, pps_hosts))
        broadcasting_starttime = 0
        broadcasting_endtime = 0
        recording_delay = 60
        common_copy = "COMMON"
        unique_copy = "UNIQUE"
        source_region = cfg["recorderRegion"]
        dest_region = cfg["recorderRegion"]
        copy_type = unique_copy
        ingest_delay = 120

        srt_content1 = [[
            source_region,
            str(testchannel1), dest_region, "unique"
        ]]
        srt_content2 = [[
            source_region,
            str(testchannel1), dest_region, "common"
        ]]
        srt_content_reset = [[source_region, "*", dest_region, "NoChange"]]

        # Do PPS Booking
        pps_headers = {
            'Content-Type': 'application/json',
            'Source-Type': 'WEB',
            'Source-ID': '127.0.0.1',
        }

        ###########################  USER DEFINED POST TIME IN UTC ############################
        start_delay = 5
        timeslotinminutes = cfg["test_channels"]["xlongProgramLength"]
        ingestion_time = get_utc_time_after_n_minutes(start_delay, True)
        start_time = datetime.datetime.strptime(ingestion_time,
                                                '%Y-%m-%dT%H:%M:%S')
        post_time = calendar.timegm(start_time.timetuple()) + 0.0001
        #######################################################################################

        print "\n[STEP1]: Ingest 1 event of n minutes in 3 channels with the posttime of n Minutes to the CI Host"
        ci_host = cfg['ci']['host']
        ci_port = cfg['ci']['port']
        ingest_minimum_delay = cfg['ci']['ingest_minimum_delay']
        ingest_delay_factor_per_minute = cfg['ci'][
            'ingest_delay_factor_per_minute']

        eventtitle1 = "uniquecp" + str(random.randint(1, 499))

        channel1 = ChannelLineup(BoundaryInMinutes=0)
        channel1.add_to_lineup(serviceId=testchannel1,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=1,
                               programIDPrefix=eventtitle1)
        channel1.postXmlData(ci_host, ci_port, startTime=post_time)
        channel1.writeXmlFiles(startTime=post_time)

        print "channel1 : ", channel1

        print "Wait time for the catalog ingest to get synced with the CI Host in seconds: " + str(
            ingest_delay)
        time.sleep(ingest_delay)
    except:
        message = "Testcase Failed: Error Occurred in Configuration " + PrintException(
            True)
        print message
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
        return tims_dict

    try:
        for (cmdc_host, pps_host) in hostlist:
            try:
                print "\n[STEP2]: Setting the SRT table in such a way to record the contents with unique copy type."
                configureSRT_instance = ConfigureSRT()
                configureSRT_instance.modify_srt(cfg, srt_content1)

                for householdid in householdid_list:
                    cleanup_household(cfg, pps_port, protocol, pps_host,
                                      householdid, pps_headers, timeout)

                print "\n[STEP3]: Fetching the grid response to collect the ingested content."
                gridservicelistresponse = fetch_gridRequest(
                    catalogueId, protocol, cmdc_host, cmdc_port, serviceIdlist,
                    region, timeout, printflg)
                assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

                contentId_dict_all = get_contentIddict_bytitle(
                    gridservicelistresponse, eventtitle1, ['title'])
                print "ContentID dictionary from the Grid Response\n" + str(
                    contentId_dict_all)
                assert contentId_dict_all, "Testcase Failed: Unable to Form ContentId dictionary from the Grid Response"

                contentId_list = sorted(contentId_dict_all.items(),
                                        key=lambda x: x[1])
                print "ContentId list after Sorting\n" + str(contentId_list)
                assert (
                    len(contentId_list) > 0
                ), "Testcase Failed: Unable to form ContentId list from ContentId dictionary"
                print "len(contentId_list) : ", len(contentId_list)

                content_ev1 = contentId_list[0][0]

                print "\n[STEP4]: PPS time based booking of the above event on hh-1 and hh-2 for first 3 minutes"
                starttimeinepoch = (int(math.ceil(post_time / 60.0)) * 60)
                endtimeinepoch = starttimeinepoch + (3 * 60)
                programstarttimeiniso = epoch2iso(starttimeinepoch)
                programendtimeiniso = epoch2iso(endtimeinepoch)
                payload = """{
                    "startTime": "%s",
                    "endTime": "%s",
                    "channel": "%d",
                    "checkConflicts" : true,
                    "pvr":"nPVR"
                    }
                    """ % (programstarttimeiniso, programendtimeiniso,
                           testchannel1)

                for household in householdid_list[:2]:
                    print "\nManual booking is Doing for householdId %s : " % household
                    result = do_PPSbooking_TBR(pps_port,
                                               protocol,
                                               pps_host,
                                               household,
                                               pps_headers,
                                               payload,
                                               timeout,
                                               printflg=False)
                    if result == "PASS":
                        print "Time Based booking successful for household: ", household
                    else:
                        message = "Testcase Failed: Time Based or Manual Booking failed for the channel %s" % testchannel1
                        print message
                        tims_dict = update_tims_data(tims_dict, 1, message,
                                                     [test_id])
                        return tims_dict

                print "\n[STEP5]: Confirming that hh-1 and hh-2 households has the booked item-1 in booked state."
                time.sleep(bookingCatalog_delay)
                # Getting Catalog Response for the Booked Catalog
                household_contentURI = []
                for householdid in householdid_list[:2]:
                    result_book, message, contentURI, pgm_start_waiTime, booked_catalog, contentPlaybackURI = \
                        check_time_based_book(pps_port, protocol, pps_host, householdid, timeout, programstarttimeiniso,
                                              starttimeinepoch, printflg, contentPlaybackURI=True)
                    contentpalybackuri = (householdid, contentPlaybackURI)
                    household_contentURI.append(contentpalybackuri)
                    if result_book == "PASS" and booked_catalog:
                        print "Time based booking is present in the booking catalog for %s household" % householdid
                    else:
                        message = "Testcase Failed: " + message
                        debug_print_log(pps_port, protocol, pps_host,
                                        householdid, timeout)
                        cleanup_household(cfg, pps_port, protocol, pps_host,
                                          householdid, pps_headers, timeout)
                        print message
                        tims_dict = update_tims_data(tims_dict, 1, message,
                                                     [test_id])
                        return tims_dict
                time.sleep(pgm_start_waiTime)
                time.sleep(recordingstatecheck_timedelay)

                print "\n[STEP6]: Confirming that hh-1 and hh-2 households has the booked item-1 in recording state."
                for householdid in householdid_list[:2]:
                    result_recording, message, pgm_end_waiTime, recording_catalog = \
                        check_time_based_recording(pps_port, protocol, pps_host, householdid, timeout,
                                                   programstarttimeiniso, endtimeinepoch, printflg)
                    if result_recording == "PASS":
                        print "Script will wait for " + str(pgm_end_waiTime / 60) + \
                              " minutes to complete the recording by adding the delay for the state change"
                    else:
                        message = "Testcase Failed: " + message
                        debug_print_log(pps_port, protocol, pps_host,
                                        householdid, timeout)
                        cleanup_household(cfg, pps_port, protocol, pps_host,
                                          householdid, pps_headers, timeout)
                        print message
                        tims_dict = update_tims_data(tims_dict, 1, message,
                                                     [test_id])
                        return tims_dict

                print "\n[STEP7]: Confirming that the copy type of the recording in hh-1 and hh-2 is unique copy."
                playbackuri_list = []
                for uri in household_contentURI:
                    uri_data = str(uri[1])
                    rec_id = (re.search('recId=*([^\n\r]*)',
                                        uri_data)).group(1)
                    if rec_id:
                        playbackuri_list.append(str(rec_id))
                print "Playback URI list :", playbackuri_list
                contentidlist = get_contentid_from_recid_list(
                    cfg, playbackuri_list, timeout)
                print "ContentId list :", contentidlist
                vmr_response_1 = get_vmr_response(cfg, contentidlist[0],
                                                  timeout)
                vmr_response_2 = get_vmr_response(cfg, contentidlist[1],
                                                  timeout)
                riodev_recording_hh1 = json.loads(vmr_response_1.content)[0]
                riodev_recording_hh2 = json.loads(vmr_response_2.content)[0]
                assert riodev_recording_hh1["CopyType"] == copy_type and riodev_recording_hh2["CopyType"] == copy_type,\
                    "Testcase Failed: Content %s are not in expected copy type %s in " \
                    "household 1 & household 2" % (content_ev1, copy_type)

                print "\n[STEP8]: Setting the SRT table in such a way to record the contents with common copy type."
                configureSRT_instance = ConfigureSRT()
                configureSRT_instance.modify_srt(cfg, srt_content2)

                print "\n[STEP9]: PPS time based booking of the above event on hh-3 and hh-4 for last 3 minutes"
                booking2_start_time = post_time + (6 * 60)
                starttimeinepoch = (
                    int(math.ceil(booking2_start_time / 60.0)) * 60)
                endtimeinepoch = starttimeinepoch + (3 * 60)
                programstarttimeiniso = epoch2iso(starttimeinepoch)
                programendtimeiniso = epoch2iso(endtimeinepoch)
                payload = """{
                                    "startTime": "%s",
                                    "endTime": "%s",
                                    "channel": "%d",
                                    "checkConflicts" : true,
                                    "pvr":"nPVR"
                                    }
                                    """ % (programstarttimeiniso,
                                           programendtimeiniso, testchannel1)

                for household in householdid_list[2:4]:
                    print "\nManual booking is Doing for householdId %s : " % household
                    result = do_PPSbooking_TBR(pps_port,
                                               protocol,
                                               pps_host,
                                               household,
                                               pps_headers,
                                               payload,
                                               timeout,
                                               printflg=False)
                    if result == "PASS":
                        print "Time Based booking successful for household: ", household
                    else:
                        message = "Testcase Failed: Time Based or Manual Booking failed for the channel %s" % testchannel1
                        print message
                        tims_dict = update_tims_data(tims_dict, 1, message,
                                                     [test_id])
                        return tims_dict

                print "\n[STEP10]: Confirming that hh-3 and hh-4 households has the booked item-1 in booked state."
                time.sleep(bookingCatalog_delay)
                household_contentURI = []
                # Getting Catalog Response for the Booked Catalog
                for householdid in householdid_list[2:4]:
                    result_book, message, contentURI, pgm_start_waiTime, booked_catalog, contentPlaybackURI = \
                        check_time_based_book(pps_port, protocol, pps_host, householdid, timeout, programstarttimeiniso,
                                              starttimeinepoch, printflg, contentPlaybackURI=True)
                    contentpalybackuri = (householdid, contentPlaybackURI)
                    household_contentURI.append(contentpalybackuri)
                    if result_book == "PASS" and booked_catalog:
                        print "Time based booking is present in the booking catalog for %s household" % householdid
                    else:
                        message = "Testcase Failed: " + message
                        debug_print_log(pps_port, protocol, pps_host,
                                        householdid, timeout)
                        cleanup_household(cfg, pps_port, protocol, pps_host,
                                          householdid, pps_headers, timeout)
                        print message
                        tims_dict = update_tims_data(tims_dict, 1, message,
                                                     [test_id])
                        return tims_dict
                time.sleep(pgm_start_waiTime)
                time.sleep(recordingstatecheck_timedelay)

                print "\n[STEP11]: Confirming that hh-3 and hh-4 households has the booked item-1 in recording state."
                for householdid in householdid_list[2:4]:
                    result_recording, message, pgm_end_waiTime, recording_catalog = \
                        check_time_based_recording(pps_port, protocol, pps_host, householdid, timeout,
                                                   programstarttimeiniso, endtimeinepoch, printflg)
                    if result_recording == "PASS":
                        print "Script will wait for " + str(pgm_end_waiTime / 60) + \
                              " minutes to complete the recording by adding the delay for the state change"
                    else:
                        message = "Testcase Failed: " + message
                        debug_print_log(pps_port, protocol, pps_host,
                                        householdid, timeout)
                        cleanup_household(cfg, pps_port, protocol, pps_host,
                                          householdid, pps_headers, timeout)
                        print message
                        tims_dict = update_tims_data(tims_dict, 1, message,
                                                     [test_id])
                        return tims_dict

                print "\n[STEP12]: Confirming that the copy type of the recording in hh-3 and hh-4 is common copy."
                playbackuri_list = []
                for uri in household_contentURI:
                    uri_data = str(uri[1])
                    rec_id = (re.search('recId=*([^\n\r]*)',
                                        uri_data)).group(1)
                    if rec_id:
                        playbackuri_list.append(str(rec_id))
                print "Playback URI list :", playbackuri_list
                contentidlist = get_contentid_from_recid_list(
                    cfg, playbackuri_list, timeout)
                print "ContentId list :", contentidlist
                vmr_response_1 = get_vmr_response(cfg, contentidlist[0],
                                                  timeout)
                vmr_response_2 = get_vmr_response(cfg, contentidlist[1],
                                                  timeout)
                riodev_recording_hh1 = json.loads(vmr_response_1.content)[0]
                riodev_recording_hh3 = json.loads(vmr_response_2.content)[0]
                assert riodev_recording_hh1["CopyType"] == common_copy and \
                       riodev_recording_hh3["CopyType"] == common_copy, \
                    "Testcase Failed: Content %s are not in expected copy type %s in " \
                    "household 3 & household 4" % (content_ev1, common_copy)
                message = "Testcase Passed: copy type of the recording in hh-3 and hh-4 is common copy"
                tims_dict = update_tims_data(tims_dict, 0, message, [test_id])

            except AssertionError as ae:
                message = str(ae)
                tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

            except Exception as e:
                message = str(e)
                tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

    except AssertionError as ae:
        message = str(ae)
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

    except Exception as e:
        message = str(e)
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

    finally:
        for householdid in householdid_list:
            cleanup_household(cfg, pps_port, protocol, pps_host, householdid,
                              pps_headers, timeout)
        configureSRT_instance = ConfigureSRT()
        configureSRT_instance.modify_srt(cfg, srt_content_reset)
        print message
        return tims_dict
def doit_wrapper(cfg, printflg=False):

    message = ""
    status = 3
    test_id = "TC9834"
    tims_dict = {
        test_id: ["US80592", message, status],
    }
    print "%s: Big Red Button - Change SRT when recording is ongoing." % (
        test_id)

    try:
        # announce
        abspath = os.path.abspath(__file__)
        scriptName = os.path.basename(__file__)
        (test, ext) = os.path.splitext(scriptName)
        print "Starting test " + test

        if "no_brb" in cfg["test-flags"]:
            message = "Testcase Skipped: Skipping the testcases since no_brb flag is enabled."
            print message
            tims_dict = update_tims_data(tims_dict, 2, message, [test_id])
            return tims_dict

        #Initialize the Variables
        timeout = 2
        serviceIdlist = []

        # set values based on config
        cmdc_hosts = [cfg['cmdc']['host']]
        pps_hosts = [cfg['pps']['host']]
        cmdc_port = cfg['cmdc']['port']
        pps_port = cfg['pps']['port']
        catalogueId = cfg['catalogueId']
        protocol = cfg['protocol']
        region = cfg['region']

        # Handle if the there are less channels than the threshold.
        threshold_channels = 17
        channelfilter1 = []
        for channels in cfg['test_channels'].keys():
            if channels.startswith("GenericCh"):
                channelfilter1.append(channels)
        if len(channelfilter1) < threshold_channels:
            message = "Skipping this TC since number of channels are less than 17."
            print message
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
            return tims_dict

        testchannel1 = cfg['test_channels']['GenericCh1']['ServiceId']
        testchannel2 = cfg['test_channels']['GenericCh2']['ServiceId']

        serviceIdlist.append(unicode(testchannel1))
        serviceIdlist.append(unicode(testchannel2))

        prefix = cfg['feature']['household_prefix']
        fetch_bookingcatalog_delay = cfg['pps']['fetch_bookingCatalog_delay']
        recordingstatecheck_timedelay = cfg['pps']['booked_to_recording_delay']
        householdid1 = prefix + '1'
        householdid2 = prefix + '2'
        householdid3 = prefix + '3'
        householdid4 = prefix + '4'
        householdid_list = [
            householdid1, householdid2, householdid3, householdid4
        ]
        hostlist = list(itertools.product(cmdc_hosts, pps_hosts))
        broadcasting_starttime = 0
        broadcasting_endtime = 0
        recording_delay = 60
        ingest_delay = 120
        srt_change_delay = 120
        common_copy = "COMMON"
        unique_copy = "UNIQUE"
        source_region = cfg["recorderRegion"]
        dest_region = cfg["recorderRegion"]
        copy_type = unique_copy

        srt_content = [
            [source_region, "*", dest_region, "unique"],
        ]
        srt_content_change1 = [
            [source_region, "*", dest_region, "common"],
        ]
        srt_content_change2 = [
            [],
        ]
        srt_content_reset = [
            [source_region, "*", dest_region, "NoChange"],
        ]

        # Do PPS Booking
        pps_headers = {
            'Content-Type': 'application/json',
            'Source-Type': 'WEB',
            'Source-ID': '127.0.0.1',
        }

        ###########################  USER DEFINED POST TIME IN UTC ############################
        start_delay = 5
        timeslotinminutes = cfg["test_channels"]["longProgramLength"]  # * 6
        ingestion_time = get_utc_time_after_n_minutes(start_delay, True)
        start_time = datetime.datetime.strptime(ingestion_time,
                                                '%Y-%m-%dT%H:%M:%S')
        post_time = calendar.timegm(start_time.timetuple()) + 0.0001
        #######################################################################################

        print "### STEP1: Ingest an event of n minutes with the posttime of n Minutes to the CI Host ######## \n \n"
        ci_host = cfg['ci']['host']
        ci_port = cfg['ci']['port']
        ingest_minimum_delay = cfg['ci']['ingest_minimum_delay']
        ingest_delay_factor_per_minute = cfg['ci'][
            'ingest_delay_factor_per_minute']

        eventtitle1 = "commoncp" + str(random.randint(1, 499))

        channel1 = ChannelLineup(BoundaryInMinutes=0)
        channel1.add_to_lineup(serviceId=testchannel1,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=2,
                               programIDPrefix=eventtitle1)
        channel1.postXmlData(ci_host, ci_port, startTime=post_time)
        channel1.writeXmlFiles(startTime=post_time)

        print "channel1 : ", channel1

        channel2 = ChannelLineup(BoundaryInMinutes=0)
        channel2.add_to_lineup(serviceId=testchannel2,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=2,
                               programIDPrefix=eventtitle1)
        channel2.postXmlData(ci_host, ci_port, startTime=post_time)
        channel2.writeXmlFiles(startTime=post_time)

        print "channel2 : ", channel2

        print "Wait time for the catalog ingest to get synced with the CI Host in seconds: " + str(
            ingest_delay)
        time.sleep(ingest_delay)

    except:
        message = "Testcase Failed: Error Occurred in Configuration " + PrintException(
            True)
        print message
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
        return tims_dict

    for (cmdc_host, pps_host) in hostlist:
        try:

            print "### STEP2: Setting the SRT table in such a way to record the contents with unique copy type. ###### \n \n"
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content)

            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host,
                                  householdid, pps_headers, timeout)

            print "### STEP3: Fetching the grid response to collect the ingested content. ##### \n \n"
            gridservicelistresponse = fetch_gridRequest(catalogueId, protocol, \
                      cmdc_host, cmdc_port, serviceIdlist, region, timeout, printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(
                gridservicelistresponse, eventtitle1, ['title'])
            print "ContentID dictionary from the Grid Response\n" + str(
                contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable to Form ContentId dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            #contentId_list = get_contentIdlist_allcontentiddict_channellineup(contentId_dict_all, printflg)
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (
                len(contentId_list) > 0
            ), "Testcase Failed: Unable to form ContentId list from ContentId dictionary"
            print "len(contentId_list) : ", len(contentId_list)

            content_ev1 = contentId_list[0][0]
            content_ev2 = contentId_list[1][0]
            content_ev3 = contentId_list[2][0]
            content_ev4 = contentId_list[3][0]

            payload_ev1 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev1)

            payload_ev2 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev2)

            payload_ev3 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev3)

            payload_ev4 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev4)

            print "About to start the event 1 booking\n\n"
            print "### STEP4: PPS event-1(on hh1, hh2), event-2(on hh3, hh4) booking respectively from channel 1 & channel 2 is being done. ##### \n \n"
            for householdid in householdid_list[:2]:
                result = do_PPSbooking(pps_port, protocol, pps_host,
                                       householdid, pps_headers, payload_ev1,
                                       content_ev1, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " + str(
                        content_ev1) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            for householdid in householdid_list[2:]:
                result = do_PPSbooking(pps_port, protocol, pps_host,
                                       householdid, pps_headers, payload_ev2,
                                       content_ev2, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " + str(
                        content_ev1) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            print "### STEP5: Confirming that hh1, hh2, hh3 & hh4 has the items in booked state. ##### \n \n"
            time.sleep(fetch_bookingcatalog_delay)
            # Getting Catalog Response for the Booked Catalog
            for householdid in householdid_list[:2]:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev1:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " + str(
                        content_ev1) + " in household " + str(
                            householdid) + " is not in the BOOKED state"
                    assert False, message

            for householdid in householdid_list[2:]:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev2:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " + str(
                        content_ev1) + " in household " + str(
                            householdid) + " is not in the BOOKED state"
                    assert False, message

            broadcasting_starttime = timeDiff(broadcasting_starttime)
            recordingstatechage = recordingstatecheck_timedelay + broadcasting_starttime
            print "Script will wait for " + str(
                recordingstatechage /
                60) + " minutes to check the event recording state"
            time.sleep(recordingstatechage)
            print "Waiting additional %s seconds to workaround the state change issue." % (
                recording_delay)
            time.sleep(recording_delay)

            print "### STEP6: Confirming that all four households has the booked items in recording state. ##### \n \n"
            for householdid in householdid_list[:2]:
                recordingcatalogresult, recordingcatalogresponse = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is not in the RECORDING state".format(
                        content_ev1, householdid)
                    assert False, message

            for householdid in householdid_list[2:]:
                recordingcatalogresult, recordingcatalogresponse = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is not in the RECORDING state".format(
                        content_ev1, householdid)
                    assert False, message

            print "### STEP7: Confirming that all households, recording its "\
                       "content with copy type as unique. ##### \n \n"
            #TODO: Verify SRT is being reflected in Riodev.

            playbackuri_list = get_content_playbackURI(pps_host, pps_port, protocol,\
                        [content_ev1], householdid_list[:2], timeout)
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)

            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            riodev_recording_hh1 = json.loads(vmr_response_1.content)[0]
            riodev_recording_hh2 = json.loads(vmr_response_2.content)[0]

            assert riodev_recording_hh1["CopyType"] == copy_type and\
                   riodev_recording_hh2["CopyType"] == copy_type, \
                   "Testcase Failed: Content %s are not in expected copy \
                    type %s in household 1 & household 2."                                                          % (content_ev1, copy_type)

            print "\n" * 5

            playbackuri_list = get_content_playbackURI(pps_host, pps_port, \
                       protocol, [content_ev2], householdid_list[2:], timeout)
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            riodev_recording_hh3 = json.loads(vmr_response_1.content)[0]
            assert riodev_recording_hh3["CopyType"] == copy_type, \
                   "Testcase Failed: Content %s are not in expected \
                    copy type %s in household 3."                                                 % (content_ev1, copy_type)

            print "### STEP8: Setting the SRT table in such a way to record the "\
                   "contents with common copy type. ###### \n \n"
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content_change1)

            time.sleep(srt_change_delay)

            print "### STEP8.1: Make the SRT table empty. ###### \n \n"
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content_change2)

            print "### STEP9: PPS event-3(on hh1, hh2), event-4(on hh3, hh4) "\
                "booking respectively from channel 1 & channel 2 is being done. ##### \n \n"
            for householdid in householdid_list[:2]:
                result = do_PPSbooking(pps_port, protocol, pps_host, householdid, \
                             pps_headers, payload_ev3, content_ev3, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of \
                          content ID " + str(
                        content_ev3) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            for householdid in householdid_list[2:]:
                result = do_PPSbooking(pps_port, protocol, pps_host, \
                       householdid, pps_headers, payload_ev4, content_ev4, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of \
                               content ID " + str(
                        content_ev4) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            print "### STEP10: Confirming that the contents in hh1, hh2, "\
                       "hh3 & hh4 are in booked state. ##### \n \n"
            time.sleep(fetch_bookingcatalog_delay)
            # Getting Catalog Response for the Booked Catalog
            for householdid in householdid_list[:2]:
                catalogresult, catalogresponse = verify_booking\
                      (pps_port, protocol, pps_host, householdid, content_ev3, timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev3:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID "+str(content_ev3)\
                        +" in household "+ str(householdid)+ " is not in the BOOKED state"
                    assert False, message

            for householdid in householdid_list[2:]:
                catalogresult, catalogresponse = \
                     verify_booking(pps_port, protocol, pps_host, householdid, \
                     content_ev4, timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev4:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID "+str(content_ev4)\
                               +" in household "+ str(householdid)+ \
                               " is not in the BOOKED state"
                    assert False, message

            broadcasting_starttime = timeDiff(broadcasting_starttime)
            recordingstatechage = recordingstatecheck_timedelay + broadcasting_starttime
            print "Script will wait for " + str(recordingstatechage / 60) \
                   + " minutes to check the event recording state"
            time.sleep(recordingstatechage)
            print "Waiting additional %s seconds to workaround the "\
                   "state change issue."% (recording_delay)
            time.sleep(recording_delay)

            print "### STEP11: Confirming that all four households has "\
                       "the items in recording state. ##### \n \n"
            for householdid in householdid_list[:2]:
                recordingcatalogresult, recordingcatalogresponse = \
                    verify_recording_state(pps_port, protocol, pps_host, \
                    householdid, content_ev3, timeout)
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in household "\
                         "{1} is not in the RECORDING state".format(content_ev3, \
                         householdid)
                    assert False, message

            for householdid in householdid_list[2:]:
                recordingcatalogresult, recordingcatalogresponse = \
                      verify_recording_state(pps_port, protocol, pps_host, \
                          householdid, content_ev4, timeout)
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in household "\
                      "{1} is not in the RECORDING state".format(content_ev4, \
                      householdid)
                    assert False, message


            print "### STEP12: Confirming that all households, recording "\
                       "its content with copy type as unique. ##### \n \n"
            copy_type = unique_copy
            #TODO: Verify SRT is being reflected in Riodev.

            playbackuri_list = get_content_playbackURI(pps_host, pps_port, \
                  protocol, [content_ev3], householdid_list[:2], timeout)
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)

            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            riodev_recording_hh1 = json.loads(vmr_response_1.content)[0]
            riodev_recording_hh2 = json.loads(vmr_response_2.content)[0]

            assert riodev_recording_hh1["CopyType"] == copy_type and\
                   riodev_recording_hh2["CopyType"] == copy_type, \
                   "Testcase Failed: Content %s are not in expected copy "\
                    "type %s in household 1 & household 2."% (content_ev3, copy_type)

            print "\n" * 5

            playbackuri_list = get_content_playbackURI(pps_host, pps_port, \
                   protocol, [content_ev4], householdid_list[2:], timeout)
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            riodev_recording_hh3 = json.loads(vmr_response_1.content)[0]
            assert riodev_recording_hh3["CopyType"] == copy_type, \
                 "Testcase Failed: Content %s are not in expected copy "\
                  "type %s in household 3."% (content_ev4, copy_type)

            message = "TestCase Passed : SRT is working as expected."
            tims_dict = update_tims_data(tims_dict, 0, message, [test_id])

        except AssertionError as ae:
            message = str(ae)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        except Exception as e:
            message = str(e)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        finally:
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host, \
                    householdid, pps_headers, timeout)
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content_reset)
            print message
            return tims_dict
Example #6
0
def doit_wrapper(cfg, printflg=False):
    message = ""
    status = 3
    test_id = "TC10118"
    tims_dict = {test_id: ["US78110", message, status]}
    print "%s: BRB - Dual VMR - Redirect the request to different VMR for a single channel in " \
          "Common copy mode and playback the content." % (test_id)

    try:
        # announce
        # abspath = os.path.abspath(__file__)
        scriptName = os.path.basename(__file__)
        (test, ext) = os.path.splitext(scriptName)
        print "Starting test " + test

        if "no_brb" in cfg["test-flags"]:
            message = "Testcase Skipped: Skipping the testcases since no_brb flag is enabled."
            print message
            tims_dict = update_tims_data(tims_dict, 2, message, [test_id])
            return tims_dict

        # Initialize the Variables
        timeout = 2
        serviceIdlist = []

        # set values based on config
        cmdc_hosts = [cfg['cmdc']['host']]
        pps_hosts = [cfg['pps']['host']]
        upm_hosts = [cfg['upm']['host']]
        cmdc_port = cfg['cmdc']['port']
        pps_port = cfg['pps']['port']
        catalogueId = cfg['catalogueId']
        protocol = cfg['protocol']
        region = cfg['region']

        # Handle if the there are less channels than the threshold.
        threshold_channels = 17
        channelfilter1 = []
        for channels in cfg['test_channels'].keys():
            if channels.startswith("GenericCh"):
                channelfilter1.append(channels)
        if len(channelfilter1) < threshold_channels:
            message = "Skipping this TC since number of channels are less than 17."
            print message
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
            return tims_dict

        # Hardcoded the channel due to UUID channel issue while routing and recording.
        ch1 = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "channels"][1]
        ch2 = cfg["feature"]["brb"]["Recorderegions"]["v2pcVMR"]["channels"][0]
        testchannel1 = cfg['test_channels'][ch1]['ServiceId']
        testchannel2 = cfg['test_channels'][ch2]['ServiceId']

        serviceIdlist.append(unicode(testchannel1))
        serviceIdlist.append(unicode(testchannel2))

        prefix = cfg['basic_feature']['household_prefix']
        fetch_bookingcatalog_delay = cfg['pps']['fetch_bookingCatalog_delay']
        recordingstatecheck_timedelay = cfg['pps']['booked_to_recording_delay']
        recording_to_recorded_delay = cfg['pps']['recording_to_recorded_delay']
        householdid1 = prefix + '1'
        householdid2 = prefix + '2'
        householdid3 = prefix + '3'
        householdid4 = prefix + '4'
        householdid_list = [
            householdid1, householdid2, householdid3, householdid4
        ]
        hostlist = list(itertools.product(cmdc_hosts, pps_hosts, upm_hosts))
        broadcasting_starttime = 0
        broadcasting_endtime = 0
        recording_delay = 60
        common_copy = "COMMON"
        unique_copy = "UNIQUE"
        source_region = cfg["feature"]["brb"]["Recorderegions"]["v2pcVMR"][
            "name"]
        dest_region = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "name"]
        copy_type = unique_copy
        ingest_delay = 120
        vmr = cfg['feature']['brb']['Recorderregions']['v2pcVMR']['host']
        aws_vmr = cfg['feature']['brb']['Recorderregions']['standaloneVMR'][
            'host']
        print "VMR : ", vmr
        print "AWS_VMR :", aws_vmr

        region_index = 5
        contentURI_list = []

        srt_content = [[
            source_region,
            str(testchannel1), dest_region, common_copy
        ]]
        srt_content_reset = [[source_region, "*", source_region, "NoChange"]]

        # Do PPS Booking
        pps_headers = {
            'Content-Type': 'application/json',
            'Source-Type': 'WEB',
            'Source-ID': '127.0.0.1',
        }

        ###########################  USER DEFINED POST TIME IN UTC ############################
        start_delay = 5
        timeslotinminutes = cfg["test_channels"]["longProgramLength"] * 2
        ingestion_time = get_utc_time_after_n_minutes(start_delay, True)
        start_time = datetime.datetime.strptime(ingestion_time,
                                                '%Y-%m-%dT%H:%M:%S')
        post_time = calendar.timegm(start_time.timetuple()) + 0.0001
        #######################################################################################

        print "### STEP1: Ingest an event of n minutes with the " \
              "posttime of n Minutes to the CI Host ######## \n \n"
        ci_host = cfg['ci']['host']
        ci_port = cfg['ci']['port']
        ingest_minimum_delay = cfg['ci']['ingest_minimum_delay']
        ingest_delay_factor_per_minute = cfg['ci'][
            'ingest_delay_factor_per_minute']

        eventtitle1 = test_id + str(random.randint(1, 499))

        channel1 = ChannelLineup(BoundaryInMinutes=0)
        channel1.add_to_lineup(serviceId=testchannel1, \
                               timeSlotLengthMinutes=timeslotinminutes, timeSlotCount=1, \
                               programIDPrefix=eventtitle1)
        channel1.postXmlData(ci_host, ci_port, startTime=post_time)
        channel1.writeXmlFiles(startTime=post_time)

        print "channel1 : ", channel1

        channel2 = ChannelLineup(BoundaryInMinutes=0)
        channel2.add_to_lineup(serviceId=testchannel2, \
                               timeSlotLengthMinutes=timeslotinminutes, timeSlotCount=1, \
                               programIDPrefix=eventtitle1)
        channel2.postXmlData(ci_host, ci_port, startTime=post_time)
        channel2.writeXmlFiles(startTime=post_time)

        print "channel2 : ", channel2

        print "Wait time for the catalog ingest to " \
              "get synced with the CI Host in seconds: " + str(ingest_delay)
        time.sleep(ingest_delay)

    except:
        message = "Testcase Failed: Error Occurred in Configuration " + PrintException(
            True)
        print message
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
        return tims_dict

    for (cmdc_host, pps_host, upm_host) in hostlist:
        try:

            print "### STEP2 : Ensure four household present in the system pointing to " \
                  "RR1 recording region. ###\n"
            for household in householdid_list:
                hh_region = get_household_region(cfg, upm_host, household,
                                                 timeout)
                assert hh_region == source_region, "Testcase Fail : Household %s not in the " \
                                                   "source region %s" % (household, source_region)

            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host, \
                                  householdid, pps_headers, timeout)

            print "### STEP3: Modify the SRT in such a way to record the contents from channel 1 " \
                  "with common copy type in RR2 recording region. ###### \n"
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.set_srt_availability(cfg, state="Enable")
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content)


            gridservicelistresponse = fetch_gridRequest(catalogueId, protocol, cmdc_host, cmdc_port, \
                                                        serviceIdlist, region, timeout, printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(gridservicelistresponse, \
                                                           eventtitle1, ['title'])
            print "ContentID dictionary from the Grid Response\n" + str(
                contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable to Form ContentId " \
                                       "dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (len(contentId_list) > 0), "Testcase Failed: Unable to form ContentId " \
                                              "list from ContentId dictionary"

            content_ev1 = contentId_list[0][0]
            content_ev2 = contentId_list[1][0]

            payload_ev1 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev1)

            payload_ev2 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev2)

            print "### STEP4. Perform booking on all four households for the ingested contents."
            print "        4.1. Perform the booking on channel 1 on hh 1 & hh2."
            print "        4.2. Perform the booking on channel 2 on hh 3 & hh4. ####### \n"
            for householdid in householdid_list[:2]:
                result = do_PPSbooking(pps_port, protocol, pps_host, householdid, \
                                       pps_headers, payload_ev1, content_ev1, timeout, printflg)
                assert result == "PASS", "Testcase Failed:Unable to do pps booking of content ID " \
                                         + str(content_ev1) + " in household " + str(householdid)

            for householdid in householdid_list[2:4]:
                result = do_PPSbooking(pps_port, protocol, pps_host, householdid, \
                                       pps_headers, payload_ev2, content_ev2, timeout, printflg)
                assert result == "PASS", "Testcase Failed:Unable to do pps booking of content ID " \
                                         + str(content_ev2) + " in household " + str(householdid)

            print "### STEP5: Wait for the program to start its recording on all " \
                  "four households. ##### \n \n"
            time.sleep(fetch_bookingcatalog_delay)
            # Getting Catalog Response for the Booked Catalog
            for householdid in householdid_list[:2]:
                catalogresult, catalogresponse = verify_booking(pps_port, protocol, pps_host, \
                                                                householdid, content_ev1, timeout)
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            contentURI = items['uri']
                            contentURI_list.append(contentURI)
                            if items['scheduleInstance'] == content_ev1:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " + str(content_ev1) + " in household " \
                              + str(householdid) + " is not in the BOOKED state"
                    assert False, message

            for householdid in householdid_list[2:4]:
                catalogresult, catalogresponse = verify_booking(pps_port, protocol, pps_host, \
                                                                householdid, content_ev2, timeout)
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            contentURI = items['uri']
                            contentURI_list.append(contentURI)
                            if items['scheduleInstance'] == content_ev2:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " \
                              + str(content_ev1) + " in household " + str(householdid) \
                              + " is not in the BOOKED state"
                    assert False, message

            broadcasting_starttime = timeDiff(broadcasting_starttime)
            print "broadcasting_starttime :", broadcasting_starttime
            recordingstatechage = recordingstatecheck_timedelay + broadcasting_starttime
            print "Script will wait for " + str(recordingstatechage / 60) \
                  + " minutes to check the event recording state"
            time.sleep(recordingstatechage)
            print "Waiting additional %s seconds to workaround the " \
                  "state change issue." % (recording_delay)
            time.sleep(recording_delay)

            print "Verifying Recording state"
            for householdid in householdid_list[:2]:
                recrding_res1, recrding_resp1 = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                if recrding_res1 != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is " \
                              "not in the RECORDING state".format(content_ev1, householdid)
                    assert False, message

            for householdid in householdid_list[2:4]:
                recrding_res2, recrding_resp2 = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)
                if recrding_res2 != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is not in the " \
                              "RECORDING state".format(content_ev1, householdid)
                    assert False, message

            print "### STEP6: Confirm from VMR API response that recorded contents."
            print "        6.1. Content from channel 1 recorded on hh1 & hh2 with " \
                  "common copy type in RR2 recording region."

            cfg['vmr']['host'] = aws_vmr
            playbackuri_list = get_content_playbackURI(pps_host, pps_port, protocol, [content_ev1], \
                                                       householdid_list[:2], timeout)
            assert playbackuri_list is not None, "TestCase failed: Unable to get recording catalog"
            print "Playback URI list :", playbackuri_list
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            print "ContentId list :", contentidlist
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            assert vmr_response_1.content != 'null', "TestCase failed: VMR response for ContentId: %s " \
                                                     "is Null." % contentidlist[0]
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            assert vmr_response_2.content != 'null', "TestCase failed: VMR response for ContentId: %s " \
                                            "is Null." % contentidlist[1]

            recording_hh1 = json.loads(vmr_response_1.content)[0]
            recording_hh2 = json.loads(vmr_response_2.content)[0]

            region_hh1 = recording_hh1['A8UpdateURL'].split('/')[region_index]
            region_hh2 = recording_hh2['A8UpdateURL'].split('/')[region_index]

            copy_type_hh1 = recording_hh1["CopyType"]
            copy_type_hh2 = recording_hh2["CopyType"]

            print "recording_hh1 : ", recording_hh1
            print "recording_hh2 : ", recording_hh2

            print "region_hh1 : ", region_hh1
            print "region_hh2 : ", region_hh2
            assert copy_type_hh1 == copy_type_hh2 == common_copy , \
                "Testcase Failed: Content %s are not in expected copy " \
                "type %s in household 1 and 2." % (content_ev1, copy_type)

            assert region_hh1 == region_hh2 == dest_region, \
                "Testcase Failed: Content %s are not in expected region " \
                " %s in household 1 & household 2." % (content_ev1, dest_region)

            print "        6.2. Content from channel 2 recorded on hh3 & hh4 with " \
                  "default copy type in RR1 recording region.##### \n \n"

            cfg['vmr']['host'] = vmr
            playbackuri_list = get_content_playbackURI(pps_host, pps_port, protocol, [content_ev2], \
                                                       householdid_list[2:4], timeout)
            assert playbackuri_list is not None, "TestCase failed: Unable to get recording catalog"
            print "Playback URI list :", playbackuri_list
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            print "ContentId list :", contentidlist
            vmr_response_3 = get_vmr_response(cfg, contentidlist[0], timeout)
            assert vmr_response_3.content != 'null', "TestCase failed: VMR response for ContentId: %s " \
                                            "is Null." % contentidlist[0]

            vmr_response_4 = get_vmr_response(cfg, contentidlist[1], timeout)
            assert vmr_response_4.content != 'null', "TestCase failed: VMR response for ContentId: %s " \
                                            "is Null." % contentidlist[1]

            recording_hh3 = json.loads(vmr_response_3.content)[0]
            recording_hh4 = json.loads(vmr_response_4.content)[0]

            region_hh3 = recording_hh3['A8UpdateURL'].split('/')[region_index]
            region_hh4 = recording_hh4['A8UpdateURL'].split('/')[region_index]

            copy_type_hh3 = recording_hh3["CopyType"]
            copy_type_hh4 = recording_hh4["CopyType"]
            print "recording_hh3 : ", recording_hh3
            print "recording_hh4 : ", recording_hh4

            print "region_hh3 : ", region_hh3
            print "region_hh4 : ", region_hh4

            assert copy_type_hh3 == copy_type_hh4 == unique_copy, \
                "Testcase Failed: Content %s are not in expected copy " \
                "type %s in household 3 and 4." % (content_ev2, copy_type)

            assert region_hh3 == region_hh4 == source_region, \
                "Testcase Failed: Content %s are not in expected region " \
                " %s in household 3 and 4." % (content_ev2, source_region)

            del_count = 0
            for contentURI in contentURI_list:
                delete_result = delete_PPSrecording(pps_port, protocol, pps_host, pps_headers, \
                                                    timeout, contentURI, printflg)
                if delete_result == "PASS":
                    del_count += 1

            assert del_count == 4, "TestCase Failed: Unable to delete all recordings"
            print "Checking again in the Recording catalog"
            for householdid in householdid_list[:2]:
                recrding_res1, recrding_resp1 = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                if recrding_res1 == "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is " \
                              " in the RECORDING state".format(content_ev1, householdid)
                    assert False, message

            for householdid in householdid_list[2:4]:
                recrding_res2, recrding_resp2 = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)
                if recrding_res2 == "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is in " \
                              "RECORDING state".format(content_ev1, householdid)
                    assert False, message

            message = "Testcase Passed: SRT is working as expected."

        except AssertionError as ae:
            message = str(ae)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        except Exception as e:
            message = str(e)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        finally:
            print "### STEP7. Cleanup the households and srt table. ##### \n \n"
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host, \
                                  householdid, pps_headers, timeout)
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content_reset)
            print message
            return tims_dict
Example #7
0
def doit_wrapper(cfg, printflg=False):
    message = ""
    status = 3
    test_id = "TC10124"
    tims_dict = {test_id: ["US78110", message, status]}
    print "%s: BRB - Dual VMR - Redirect recording from HH with invalid VMR before " \
          "scheduling from invalid VMR to valid VMR" % (test_id)

    try:
        # announce
        # abspath = os.path.abspath(__file__)
        scriptName = os.path.basename(__file__)
        (test, ext) = os.path.splitext(scriptName)
        print "Starting test " + test

        if "no_brb" in cfg["test-flags"]:
            message = "Testcase Skipped: Skipping the testcase since no_brb flag is enabled."
            print message
            tims_dict = update_tims_data(tims_dict, 2, message, [test_id])
            return tims_dict

        # Initialize the Variables
        timeout = 2
        serviceIdlist = []

        # set values based on config
        cmdc_hosts = [cfg['cmdc']['host']]
        pps_hosts = [cfg['pps']['host']]
        upm_hosts = [cfg['upm']['host']]
        upm_port = cfg['upm']['port']
        cmdc_port = cfg['cmdc']['port']
        pps_port = cfg['pps']['port']
        catalogueId = cfg['catalogueId']
        protocol = cfg['protocol']
        region = cfg['region']

        ch1 = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "channels"][0]

        testchannel1 = cfg['test_channels'][ch1]['ServiceId']
        testchannel1_uuid = cfg['test_channels'][ch1]['UUID']

        serviceIdlist.append(unicode(testchannel1))

        prefix = cfg['basic_feature']['household_prefix']
        fetch_bookingcatalog_delay = cfg['pps']['fetch_bookingCatalog_delay']
        recordingstatecheck_timedelay = cfg['pps']['booked_to_recording_delay']
        householdid4 = prefix + '7'
        householdid_list = [householdid4]
        hostlist = list(itertools.product(cmdc_hosts, pps_hosts, upm_hosts))
        recording_delay = 180

        cmdcRegion = cfg['cmdcRegion']
        adZone = cfg['adZone']
        marketingTarget = cfg['marketingTarget']

        invalid_region = "Invalid"
        source_region = cfg["feature"]["brb"]["Recorderegions"]["v2pcVMR"][
            "name"]
        dest_region = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "name"]
        srt_content_reset = [[source_region, "*", source_region, "NoChange"]]
        common_copy = "COMMON"
        unique_copy = "UNIQUE"
        vmr = cfg["vmr"]["instances"]["v2pcVMR"]
        aws_vmr = cfg["vmr"]["instances"]["standaloneVMR"]
        print "VMR : ", vmr
        print "AWS_VMR :", aws_vmr
        region_index = 5

        srt_content = [[invalid_region, '*', dest_region, common_copy]]

        # Do PPS Booking
        pps_headers = {
            'Content-Type': 'application/json',
            'Source-Type': 'WEB',
            'Source-ID': '127.0.0.1',
        }

        # ##########################  USER DEFINED POST TIME IN UTC ############################
        start_delay = 3
        timeslotinminutes = cfg["test_channels"]["longProgramLength"]
        ingestion_time = get_utc_time_after_n_minutes(start_delay, True)
        start_time = datetime.datetime.strptime(ingestion_time,
                                                '%Y-%m-%dT%H:%M:%S')
        post_time = calendar.timegm(start_time.timetuple()) + 0.0001
        #######################################################################################

        print "### STEP1: Ingest an event on channel 1  with 5 minutes duration and 5 minutes " \
              "post time. ###\n"
        ci_host = cfg['ci']['host']
        ci_port = cfg['ci']['port']
        ingest_minimum_delay = cfg['ci']['ingest_minimum_delay']
        ingest_delay_factor_per_minute = cfg['ci'][
            'ingest_delay_factor_per_minute']

        eventtitle1 = "TC10124" + str(random.randint(1, 499))
        channel1 = ChannelLineup(BoundaryInMinutes=0)
        channel1.add_to_lineup(serviceId=testchannel1,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=1,
                               programIDPrefix=eventtitle1)
        channel1.postXmlData(ci_host, ci_port, startTime=post_time)
        channel1.writeXmlFiles(startTime=post_time)

        print "channel1 : ", channel1

        length = channel1.getTotalLength()
        sleep_channel = ingest_minimum_delay + length * ingest_delay_factor_per_minute

        print "Wait time for the catalog ingest to " \
              "get synced with the CI Host in seconds: " + str(sleep_channel)
        time.sleep(sleep_channel)

    except:
        message = "Testcase Failed: Error Occurred in Configuration " + PrintException(
            True)
        print message
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
        return tims_dict

    for (cmdc_host, pps_host, upm_host) in hostlist:
        try:
            # Create HH in Invalid recorder region
            print "### STEP2: Ensure an household present in the system pointing to invalid " \
                  "recording region. ###"

            for householdid in householdid_list:
                hh_headers = {
                    'Content-Type': 'application/json',
                    'Source-Type': 'WEB',
                    'Source-ID': '127.0.0.1',
                    'Accept': 'application/json'
                }
                hh_create_payload = """
                                        {
                                          "householdId" : "%s",
                                          "householdStatus" : "ACTIVATED",
                                          "operateStatus": "ACTIVE",
                                          "locale" : {
                                                "region" : "%s",
                                                "cmdcRegion":"%s",
                                                "adZone": "%s",
                                                    "marketingTarget": "%s",
                                                    "recorderRegion": "%s"
                                                     },
                                          "cDvrPvr": true
                                    }
                                    """ % (householdid, region, cmdcRegion,
                                           adZone, marketingTarget,
                                           invalid_region)

                print "Create HouseHold Payload :", hh_create_payload

                create_hh = create_household(protocol, upm_port, householdid,
                                             upm_host, hh_headers,
                                             hh_create_payload)
                assert create_hh, "Testcase Failed: Unable to create household %s " \
                                  "in RR %s" %(householdid, dest_region)

                setoffers = setCdvrSubscriptionOffers(cfg, householdid)
                assert setoffers, "Testcase Failed : Unable to set offers for %s" % householdid

            for household in householdid_list:
                hh_region = get_household_region(cfg, upm_host, household,
                                                 timeout)
                assert hh_region == invalid_region, "Testcase Fail : Household %s not in the " \
                                                   "invalid region %s" % (household, invalid_region)

            print "### STEP3 : Modify the SRT in such a way to record the contents from any " \
                  "channel and an hh pointing to an invalid region with Common copy type in " \
                  "RR2 recording region. ###\n"

            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content)

            # Cleaning up the household
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host,
                                  householdid, pps_headers, timeout)

            gridservicelistresponse = fetch_gridRequest(
                catalogueId, protocol, cmdc_host, cmdc_port, [
                    unicode(testchannel1),
                ], region, timeout, printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(
                gridservicelistresponse, eventtitle1, ['title'])
            print "ContentID dictionary from the Grid Response\n" + str(
                contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable " \
                                       "to Form ContentId dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (len(contentId_list) > 0), "Testcase Failed: Unable " \
                                              "to form ContentId list from ContentId dictionary"
            print "len(contentId_list) : ", len(contentId_list)

            content_ev1 = contentId_list[0][0]
            ev1_broadcast_start_time = contentId_list[0][1][0]

            print "### STEP4. Perform booking on the household for the ingested content.###\n"
            payload_ev1 = """{
                                "scheduleInstanceId" : "%s",
                                "checkConflicts" : true,
                                "pvr":"nPVR"
                                }""" % (content_ev1)

            for householdid in householdid_list:
                result = do_PPSbooking(pps_port, protocol, pps_host, householdid, \
                                       pps_headers, payload_ev1, content_ev1, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev1) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            for householdid in householdid_list:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                print "Booking response of Event 1:", catalogresult
                assert catalogresult == "PASS", "TestCase  Failed : Content ID " + str(content_ev1) \
                                                + " in household " + str(householdid) \
                                                + " is not in the BOOKED state"

            print "## STEP 5 Wait for the program to start its recording on the household. ###"
            broadcasting_starttime = get_timedifference(
                ev1_broadcast_start_time, printflg)
            recordingstatechage = recordingstatecheck_timedelay + broadcasting_starttime
            print "Script will wait for ", recordingstatechage," seconds to check the event " \
                                                               "recording state"
            time.sleep(recordingstatechage)

            for householdid in householdid_list:
                recrding_res1, recrding_resp1 = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                if recrding_res1 == "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is in the " \
                              "RECORDING state with invalid VMR".format(content_ev1, householdid)
                    assert False, message

            print "### STEP 6. Confirm from VMR API response that recording is not happening. ###\n"
            cfg['vmr']['host'] = aws_vmr
            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev1],
                                                       householdid_list,
                                                       timeout)
            print "Playback URI list :", playbackuri_list
            assert not playbackuri_list, "Testcase Failed: Content is in Recording state " \
                                              "which is not as expected"

            cfg['vmr']['host'] = vmr
            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev1],
                                                       householdid_list,
                                                       timeout)
            print "Playback URI list :", playbackuri_list
            assert not playbackuri_list, "Testcase Failed: Content is in Recording state " \
                                                 "which is not as expected"

            message = "TestCase Passed : Recording is not happening with the HH created in " \
                      "Invalid Recorder region"
            tims_dict = update_tims_data(tims_dict, 0, message, [test_id])

        except AssertionError as ae:
            message = str(ae)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        except Exception as e:
            message = str(e)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        finally:
            print "### STEP7. Cleanup the households and srt table. ###\n"
            for householdid in householdid_list:
                delete_household(protocol, upm_port, householdid, upm_host)
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content_reset)
            print message
            return tims_dict
Example #8
0
def doit_wrapper(cfg, printflg=False):
    message = ""
    status = 3
    test_id = "TC10141"
    tims_dict = {test_id: ["US78110", message, status]}
    print "%s: BRB - Dual VMR - Redirect recording before scheduling from a VMR to another VMR " \
          "for a single channel in Common copy mode and playback the recording once done" % (test_id)

    try:
        # announce
        abspath = os.path.abspath(__file__)
        scriptName = os.path.basename(__file__)
        (test, ext) = os.path.splitext(scriptName)
        print "Starting test " + test

        if "no_brb" in cfg["test-flags"]:
            message = "Testcase Skipped: Skipping the testcases since no_brb flag is enabled."
            print message
            tims_dict = update_tims_data(tims_dict, 2, message, [test_id])
            return tims_dict

        # Initialize the Variables
        timeout = 2
        serviceIdlist = []

        # set values based on config
        cmdc_hosts = [cfg['cmdc']['host']]
        pps_hosts = [cfg['pps']['host']]
        upm_hosts = [cfg['upm']['host']]
        cmdc_port = cfg['cmdc']['port']
        pps_port = cfg['pps']['port']
        catalogueId = cfg['catalogueId']
        protocol = cfg['protocol']
        region = cfg['region']

        # Playback config
        prmsupportedflag = cfg['prm_supported']
        proxyhostcheckflag = cfg['proxyHostNeeded']
        proxy_host = cfg['proxyhost']['host']
        proxy_port = cfg['proxyhost']['port']
        contentplayback_host = cfg['contentplayback']['host']
        contentplayback_host_aws = "cdvrDash.mpe-58a1293c2e83f6b7.elb.us-east-1.amazonaws.com"
        contentplayback_port = cfg['contentplayback']['port']
        contentplayback_url = cfg['contentplayback']['url']
        contentplayback_url_aws = "/cdvrDash-cisc/"
        rm_host = cfg['rm']['host']

        # Handle if the there are less channels than the threshold.
        threshold_channels = 17
        channelfilter1 = []
        for channels in cfg['test_channels'].keys():
            if channels.startswith("GenericCh"):
                channelfilter1.append(channels)
        if len(channelfilter1) < threshold_channels:
            message = "Skipping this TC since number of channels are less than 17."
            print message
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
            return tims_dict

        ch1 = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "channels"][0]
        ch2 = cfg["feature"]["brb"]["Recorderegions"]["v2pcVMR"]["channels"][0]

        testchannel1 = cfg['test_channels'][ch1]['ServiceId']
        testchannel1_uuid = cfg['test_channels'][ch1]['UUID']
        testchannel2 = cfg['test_channels'][ch2]['ServiceId']

        serviceIdlist.append(unicode(testchannel1))
        serviceIdlist.append(unicode(testchannel2))

        prefix = cfg['basic_feature']['household_prefix']
        fetch_booking_delay = cfg['pps']['fetch_bookingCatalog_delay']
        recording_state_delay = cfg['pps']['booked_to_recording_delay']
        recording_to_recorded_delay = cfg['pps']['recording_to_recorded_delay']
        householdid1 = prefix + '1'
        householdid2 = prefix + '2'
        householdid3 = prefix + '3'
        householdid4 = prefix + '4'
        householdid_list = [
            householdid1, householdid2, householdid3, householdid4
        ]
        hostlist = list(itertools.product(cmdc_hosts, pps_hosts, upm_hosts))
        recording_delay = 60

        source_region = cfg["feature"]["brb"]["Recorderegions"]["v2pcVMR"][
            "name"]
        dest_region = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "name"]
        srt_content_reset = [[source_region, "*", source_region, "NoChange"]]
        common_copy = "COMMON"
        unique_copy = "UNIQUE"
        vmr = cfg["vmr"]["instances"]["v2pcVMR"]
        aws_vmr = cfg["vmr"]["instances"]["standaloneVMR"]
        print "VMR : ", vmr
        print "AWS_VMR :", aws_vmr
        region_index = 5

        srt_content = [[
            source_region,
            str(testchannel1_uuid), dest_region, common_copy
        ]]

        # Do PPS Booking
        pps_headers = {
            'Content-Type': 'application/json',
            'Source-Type': 'WEB',
            'Source-ID': '127.0.0.1',
        }

        # ##########################  USER DEFINED POST TIME IN UTC ###########################
        start_delay = 5
        timeslotinminutes = cfg["test_channels"]["longProgramLength"]
        ingestion_time = get_utc_time_after_n_minutes(start_delay, True)
        start_time = datetime.datetime.strptime(ingestion_time,
                                                '%Y-%m-%dT%H:%M:%S')
        post_time = calendar.timegm(start_time.timetuple()) + 0.0001
        #######################################################################################

        print "### STEP1: Ingest an event on channel 1 & channel 2 with 5 minutes duration and " \
              "5 minues post time. ##### \n \n"
        ci_host = cfg['ci']['host']
        ci_port = cfg['ci']['port']
        ingest_minimum_delay = cfg['ci']['ingest_minimum_delay']
        ingest_delay_factor_per_minute = cfg['ci'][
            'ingest_delay_factor_per_minute']

        eventtitle1 = "TC10141" + str(random.randint(1, 499))

        channel1 = ChannelLineup(BoundaryInMinutes=0)
        channel1.add_to_lineup(serviceId=testchannel1,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=1,
                               programIDPrefix=eventtitle1)
        channel1.postXmlData(ci_host, ci_port, startTime=post_time)
        channel1.writeXmlFiles(startTime=post_time)

        print "channel1 : ", channel1

        channel2 = ChannelLineup(BoundaryInMinutes=0)
        channel2.add_to_lineup(serviceId=testchannel2,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=1,
                               programIDPrefix=eventtitle1)
        channel2.postXmlData(ci_host, ci_port, startTime=post_time)
        channel2.writeXmlFiles(startTime=post_time)

        print "channel2 : ", channel2

        length = channel1.getTotalLength() + channel2.getTotalLength()
        sleep_channel = ingest_minimum_delay + length * ingest_delay_factor_per_minute

        print "Wait time for the catalog ingest to " \
              "get synced with the CI Host in seconds: " + str(sleep_channel)
        time.sleep(sleep_channel)

    except:
        message = "Testcase Failed: Error Occurred in Configuration " + PrintException(
            True)
        print message
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
        return tims_dict

    for (cmdc_host, pps_host, upm_host) in hostlist:
        try:
            print "### STEP2 :  Ensure four household present in the system pointing to RR1 " \
                  "recording region. ###\n"
            for household in householdid_list:
                hh_region = get_household_region(cfg, upm_host, household,
                                                 timeout)
                assert hh_region == source_region, "Testcase Fail : Household %s not in the " \
                                                   "source region %s" % (household, source_region)

            print "### STEP3: Modify the SRT in such a way to record the contents from channel 1 " \
                  "with common copy type in RR2 recording region. ###\n"
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content)

            # Cleaning up the household
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host,
                                  householdid, pps_headers, timeout)

            gridservicelistresponse = fetch_gridRequest(
                catalogueId, protocol, cmdc_host, cmdc_port, [
                    unicode(testchannel1),
                ], region, timeout, printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(
                gridservicelistresponse, eventtitle1, ['title'])
            print "ContentID dictionary from the Grid Response\n" + str(
                contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable " \
                                       "to Form ContentId dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (len(contentId_list) > 0), "Testcase Failed: Unable " \
                                              "to form ContentId list from ContentId dictionary"
            print "len(contentId_list) : ", len(contentId_list)

            content_ev1 = contentId_list[0][0]
            broadcast_starttime = contentId_list[0][1][0]
            broadcast_endtime = contentId_list[0][1][1]

            gridservicelistresponse = fetch_gridRequest(
                catalogueId, protocol, cmdc_host, cmdc_port, [
                    unicode(testchannel2),
                ], region, timeout, printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(
                gridservicelistresponse, eventtitle1, ['title'])
            print "ContentID dictionary from the Grid Response\n" + str(
                contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable " \
                                       "to Form ContentId dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (len(contentId_list) > 0), "Testcase Failed: Unable " \
                                              "to form ContentId list from ContentId dictionary"
            print "len(contentId_list) : ", len(contentId_list)

            content_ev2 = contentId_list[0][0]

            print "###STEP4: Perform booking on all four households for the ingested contents.###\n"
            print "## STEP 4.1. Perform the booking on channel 1 on hh 1 & hh2. ##"
            payload_ev1 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev1)

            for householdid in householdid_list[:2]:
                result = do_PPSbooking(pps_port, protocol, pps_host, householdid, \
                                       pps_headers, payload_ev1, content_ev1, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev1) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            print "## STEP 4.2. Perform the booking on channel 2 on hh 3 & hh4. ##"
            payload_ev2 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev2)

            for householdid in householdid_list[2:4]:
                result = do_PPSbooking(pps_port, protocol, pps_host, householdid, \
                                       pps_headers, payload_ev2, content_ev2, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev2) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            time.sleep(fetch_booking_delay)
            print "About to start the event 1 booking\n"
            # Getting Catalog Response for the Booked Catalog
            for householdid in householdid_list[:2]:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                print "Booking response of Event 1:", catalogresult
                assert catalogresult == "PASS", "TestCase  Failed : Content ID " + str(content_ev1) \
                                                + " in household " + str(householdid) + \
                                                " is not in the BOOKED state"

            for householdid in householdid_list[2:4]:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)
                print "Booking response of Event 2 :\n", catalogresult
                assert catalogresult == "PASS", "TestCase  Failed : Content ID " \
                                                + str(content_ev2) + " in household " + \
                                                str(householdid) + " is not in the BOOKED state"

            print "### STEP5. Wait for the program to start its recording on all four " \
                  "households.####\n"
            broadcast_starttime = get_timedifference(broadcast_starttime,
                                                     printflg)
            recordingstatechage = recording_state_delay + broadcast_starttime
            print "Script will wait for " + str(recordingstatechage / 60) \
                  + " minutes to check the event recording state"
            time.sleep(recordingstatechage)
            print "Waiting additional %s seconds to workaround the " \
                  "state change issue." % (recording_delay)
            time.sleep(recording_delay)

            for householdid in householdid_list[:2]:
                recrding_res1, recrding_resp1 = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                if recrding_res1 != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is " \
                              "not in the RECORDING state".format(content_ev1, householdid)
                    assert False, message

            for householdid in householdid_list[2:4]:
                recrding_res2, recrding_resp2 = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)
                if recrding_res2 != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is not in the " \
                              "RECORDING state".format(content_ev2, householdid)
                    assert False, message

            print "### STEP6. Confirm from VMR API response that recorded contents. ###\n"

            print "## STEP6.1. Content from channel 1 recorded on hh1 & hh2 with common copy " \
                  "type in RR2 recording region. ##"
            cfg['vmr']['host'] = aws_vmr
            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev1],
                                                       householdid_list[:2],
                                                       timeout)
            print "Playback URI list :", playbackuri_list
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            print "ContentId list :", contentidlist
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            assert vmr_response_1 and vmr_response_1.content != 'null', \
                "Testcase Failed : Unable to get the VMR response for contentId " \
                "%s" % contentidlist[0]
            assert vmr_response_2 and vmr_response_2.content != 'null', \
                "Testcase Failed : Unable to get the VMR response for contentId " \
                "%s" % contentidlist[1]
            riodev_recording_hh1 = json.loads(vmr_response_1.content)[0]
            riodev_recording_hh2 = json.loads(vmr_response_2.content)[0]
            region_hh1 = riodev_recording_hh1['A8UpdateURL'].split(
                '/')[region_index]
            region_hh2 = riodev_recording_hh2['A8UpdateURL'].split(
                '/')[region_index]
            copy_type_hh1 = riodev_recording_hh1["CopyType"]
            copy_type_hh2 = riodev_recording_hh2["CopyType"]

            print "riodev_recording_hh1 : ", riodev_recording_hh1
            print "riodev_recording_hh2 : ", riodev_recording_hh2

            print "region_hh1 : ", region_hh1
            print "region_hh2 : ", region_hh2
            assert copy_type_hh1 == copy_type_hh2 == common_copy , \
                "Testcase Failed: Content %s are not in expected copy " \
                "type %s in household 1 and 2." % (content_ev1, common_copy)

            assert region_hh1 == region_hh2 == dest_region, \
                "Testcase Failed: Content %s are not in expected region " \
                " %s in household 1 & household 2." % (content_ev1, dest_region)

            print "## STEP6.2. Content from channel 2 recorded on hh3 & hh4 with default " \
                  "copy type in RR1 recording region.##"

            cfg['vmr']['host'] = vmr
            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev2],
                                                       householdid_list[2:4],
                                                       timeout)
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            assert vmr_response_1 and vmr_response_1.content != 'null', \
                "Testcase Failed : Unable to get the VMR response for contentId " \
                "%s" % contentidlist[0]
            assert vmr_response_2 and vmr_response_2.content != 'null', \
                "Testcase Failed : Unable to get the VMR response for contentId " \
                "%s" % contentidlist[1]
            riodev_recording_hh3 = json.loads(vmr_response_1.content)[0]
            riodev_recording_hh4 = json.loads(vmr_response_2.content)[0]
            region_hh3 = riodev_recording_hh3['A8UpdateURL'].split(
                '/')[region_index]
            region_hh4 = riodev_recording_hh4['A8UpdateURL'].split(
                '/')[region_index]
            copy_type_hh3 = riodev_recording_hh3["CopyType"]
            copy_type_hh4 = riodev_recording_hh4["CopyType"]

            print "riodev_recording_hh3 : ", riodev_recording_hh3
            print "riodev_recording_hh4 : ", riodev_recording_hh4

            print "region_hh3 : ", region_hh3
            print "region_hh4 : ", region_hh4

            assert copy_type_hh3 == copy_type_hh4 == unique_copy, \
                "Testcase Failed: Content %s are not in expected copy " \
                "type %s in household 3 and 4." % (content_ev2, unique_copy)

            assert region_hh3 == region_hh4 == source_region, \
                "Testcase Failed: Content %s are not in expected region " \
                " %s in household 3 and 4." % (content_ev2, source_region)

            print "### STEP7: Wait for the content to move to recorded state and confirm " \
                  "playback happening on all households. ###\n"

            broadcast_endtime = get_timedifference(broadcast_endtime, printflg)
            recordedstatechage = recording_to_recorded_delay + broadcast_endtime
            print "Script will wait for " + str(recordedstatechage / 60) \
                  + " minutes to check the event recorded state"
            time.sleep(recordedstatechage)

            playback_event1_dict = {}
            # Verify Recorded State
            for household in householdid_list[:2]:
                recorded_res, recorded_response = verify_recorded_state(
                    pps_port, protocol, pps_host, household, [content_ev1],
                    timeout)
                assert recorded_res == "PASS", "Testcase Failed: " + recorded_response
                print "Event 1 Recorded in HH :", household
                recordedcatalogcontent = json.loads(recorded_response.content)
                for items in recordedcatalogcontent:
                    if items['scheduleInstance'] == content_ev1:
                        if items['state'] == "RECORDED":
                            contentplayuri = items['contentPlayUri']
                            recordedtitle = items['title']
                            playback_event1_dict[household] = [
                                contentplayuri, recordedtitle
                            ]
            print "Playback Content Details of Event 1:", playback_event1_dict

            playback_event2_dict = {}
            for household in householdid_list[2:4]:
                recorded_res, recorded_response = verify_recorded_state(
                    pps_port, protocol, pps_host, household, [content_ev2],
                    timeout)
                assert recorded_res == "PASS", "Testcase Failed: " + recorded_response
                print "Event 2 Recorded in HH :", household
                recordedcatalogcontent = json.loads(recorded_response.content)
                for items in recordedcatalogcontent:
                    if items['scheduleInstance'] == content_ev2:
                        if items['state'] == "RECORDED":
                            contentplayuri = items['contentPlayUri']
                            recordedtitle = items['title']
                            playback_event2_dict[household] = [
                                contentplayuri, recordedtitle
                            ]

            print "Playback Content Details of Event 2:", playback_event2_dict
            print "All the programs are in RECORDED state"
            print "\nStart Playback verification from AWS recorder region:\n"
            for hhid, val in playback_event1_dict.items():
                print "Playback for HH : %s" % hhid
                playback_rslt, playback_msg = playback_recordedevent(
                    cfg,
                    abspath,
                    test,
                    pps_headers,
                    pps_port,
                    pps_host,
                    prmsupportedflag,
                    proxyhostcheckflag,
                    protocol,
                    rm_host,
                    contentplayback_host_aws,
                    contentplayback_port,
                    proxy_host,
                    proxy_port,
                    contentplayback_url_aws,
                    val[0],
                    val[1],
                    hhid,
                    timeout,
                    printflg,
                    cleanuphousehold=False)
                assert playback_rslt == "PASS", "Testcase Failed" + playback_msg
                # print playback_msg

            print "\nStart Playback verification from OnPrem recorder region:\n"
            for hhid, val in playback_event2_dict.items():
                print "Playback for HH : %s" % hhid
                playback_rslt, playback_msg = playback_recordedevent(
                    cfg,
                    abspath,
                    test,
                    pps_headers,
                    pps_port,
                    pps_host,
                    prmsupportedflag,
                    proxyhostcheckflag,
                    protocol,
                    rm_host,
                    contentplayback_host,
                    contentplayback_port,
                    proxy_host,
                    proxy_port,
                    contentplayback_url,
                    val[0],
                    val[1],
                    hhid,
                    timeout,
                    printflg,
                    cleanuphousehold=False)
                assert playback_rslt == "PASS", "Testcase Failed" + playback_msg
                # print playback_msg

            message = "TestCase Passed : Program recorded in VMR 2 and played back successfully"
            tims_dict = update_tims_data(tims_dict, 0, message, [test_id])

        except AssertionError as ae:
            message = str(ae)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        except Exception as e:
            message = str(e)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        finally:
            print "### STEP8. Cleanup the households and srt table. ###\n"
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host, \
                                  householdid, pps_headers, timeout)
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content_reset)
            print message
            return tims_dict
Example #9
0
def doit_wrapper(cfg, printflg=False):
    message = ""
    status = 3
    test_id = "TC9839"
    tims_dict = {test_id: ["US80597", message, status]}
    print "%s: Big Red Button - rename the SRT file." % test_id

    try:
        # announce
        # abspath = os.path.abspath(__file__)
        scriptName = os.path.basename(__file__)
        (test, ext) = os.path.splitext(scriptName)
        print "Starting test " + test

        if "no_brb" in cfg["test-flags"]:
            message = "Testcase Skipped: Skipping the testcases since no_brb flag is enabled."
            print message
            tims_dict = update_tims_data(tims_dict, 2, message, [test_id])
            return tims_dict

        # Initialize the Variables
        timeout = 2
        serviceIdlist = []

        # set values based on config
        cmdc_hosts = [cfg['cmdc']['host']]
        pps_hosts = [cfg['pps']['host']]
        cmdc_port = cfg['cmdc']['port']
        pps_port = cfg['pps']['port']
        catalogueId = cfg['catalogueId']
        protocol = cfg['protocol']
        region = cfg['region']

        testchannel1 = cfg['test_channels']['GenericCh1']['ServiceId']
        testchannel2 = cfg['test_channels']['GenericCh2']['ServiceId']

        serviceIdlist.append(unicode(testchannel1))
        serviceIdlist.append(unicode(testchannel2))

        prefix = cfg['feature']['household_prefix']
        fetch_bookingcatalog_delay = cfg['pps']['fetch_bookingCatalog_delay']
        recordingstatecheck_timedelay = cfg['pps']['booked_to_recording_delay']
        householdid1 = prefix + '1'
        householdid2 = prefix + '2'
        householdid3 = prefix + '3'
        householdid4 = prefix + '4'
        householdid_list = [
            householdid1, householdid2, householdid3, householdid4
        ]
        hostlist = list(itertools.product(cmdc_hosts, pps_hosts))
        broadcasting_starttime = 0
        broadcasting_endtime = 0
        recording_delay = 60
        common_copy = "COMMON"
        unique_copy = "UNIQUE"
        source_region = cfg["recorderRegion"]
        dest_region = cfg["recorderRegion"]
        copy_type = unique_copy
        ingest_delay = 120

        srt_content = [[source_region, "*", dest_region, "unique"]]
        srt_common_content = [[source_region, "*", dest_region, "common"]]
        srt_content_reset = [[source_region, "*", dest_region, "NoChange"]]

        # Do PPS Booking
        pps_headers = {
            'Content-Type': 'application/json',
            'Source-Type': 'WEB',
            'Source-ID': '127.0.0.1',
        }

        ###########################  USER DEFINED POST TIME IN UTC ############################
        start_delay = 5
        timeslotinminutes = cfg["test_channels"]["mediumProgramLength"] * 2
        ingestion_time = get_utc_time_after_n_minutes(start_delay, True)
        start_time = datetime.datetime.strptime(ingestion_time,
                                                '%Y-%m-%dT%H:%M:%S')
        post_time = calendar.timegm(start_time.timetuple()) + 0.0001
        #######################################################################################

        print "\n[STEP1]: Ingest EV1 and EV2 of 6 minutes in 2 channels with the posttime of 10 Minutes to the " \
              "CI Host\n Ingest EV3 and EV4 of 6 minutes in 2 channels with the posttime of 20 Minutes to the CI Host"
        ci_host = cfg['ci']['host']
        ci_port = cfg['ci']['port']
        ingest_minimum_delay = cfg['ci']['ingest_minimum_delay']
        ingest_delay_factor_per_minute = cfg['ci'][
            'ingest_delay_factor_per_minute']

        eventtitle1 = "uniquecp" + str(random.randint(1, 499))

        channel1 = ChannelLineup(BoundaryInMinutes=0)
        channel1.add_to_lineup(serviceId=testchannel1,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=2,
                               programIDPrefix=eventtitle1)
        channel1.postXmlData(ci_host, ci_port, startTime=post_time)
        channel1.writeXmlFiles(startTime=post_time)

        print "channel1 : ", channel1

        channel2 = ChannelLineup(BoundaryInMinutes=0)
        channel2.add_to_lineup(serviceId=testchannel2,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=2,
                               programIDPrefix=eventtitle1)
        channel2.postXmlData(ci_host, ci_port, startTime=post_time)
        channel2.writeXmlFiles(startTime=post_time)

        print "channel2 : ", channel2

        print "Wait time for the catalog ingest to get synced with the CI Host in seconds: " + str(
            ingest_delay)
        time.sleep(ingest_delay)

    except:
        message = "Testcase Failed: Error Occurred in Configuration " + PrintException(
            True)
        print message
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
        return tims_dict

    for (cmdc_host, pps_host) in hostlist:
        try:

            print "\n[STEP2]: Setting the SRT table in such a way to record the contents with unique copy type."
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content)

            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host,
                                  householdid, pps_headers, timeout)

            print "\n[STEP3]: Fetching the grid response to collect the ingested content."
            gridservicelistresponse = fetch_gridRequest(
                catalogueId, protocol, cmdc_host, cmdc_port, serviceIdlist,
                region, timeout, printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(
                gridservicelistresponse, eventtitle1, ['title'])
            print "ContentID dictionary from the Grid Response\n" + str(
                contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable to Form ContentId dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (
                len(contentId_list) > 0
            ), "Testcase Failed: Unable to form ContentId list from ContentId dictionary"
            print "len(contentId_list) : ", len(contentId_list)

            content_ev1 = contentId_list[0][0]
            content_ev2 = contentId_list[1][0]
            content_ev3 = contentId_list[2][0]
            content_ev4 = contentId_list[3][0]

            payload_ev1 = """{
                                                    "scheduleInstanceId" : "%s",
                                                    "checkConflicts" : true,
                                                    "pvr":"nPVR"
                                                    }""" % content_ev1

            payload_ev2 = """{
                                                    "scheduleInstanceId" : "%s",
                                                    "checkConflicts" : true,
                                                    "pvr":"nPVR"
                                                    }""" % content_ev2

            payload_ev3 = """{
                                                    "scheduleInstanceId" : "%s",
                                                    "checkConflicts" : true,
                                                    "pvr":"nPVR"
                                                    }""" % content_ev3

            payload_ev4 = """{
                                                    "scheduleInstanceId" : "%s",
                                                    "checkConflicts" : true,
                                                    "pvr":"nPVR"
                                                    }""" % content_ev4

            print "About to start the event 1 booking\n\n"
            print "\n[STEP4]: Book UC EV1 from HH1, HH2 on CH1 and UC EV2 from HH3, HH4 on CH2"

            for householdid in householdid_list[:2]:
                result = do_PPSbooking(pps_port, protocol, pps_host,
                                       householdid, pps_headers, payload_ev1,
                                       content_ev1, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev1) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            for householdid in householdid_list[2:4]:
                result = do_PPSbooking(pps_port, protocol, pps_host,
                                       householdid, pps_headers, payload_ev2,
                                       content_ev2, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev1) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            print "\n[STEP5]: Confirm EV1, EV2 is in booked state"

            time.sleep(fetch_bookingcatalog_delay)
            # Getting Catalog Response for the Booked Catalog
            for householdid in householdid_list[:2]:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev1:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " + str(content_ev1) + " in household " \
                              + str(householdid) + " is not in the BOOKED state"
                    assert False, message

            for householdid in householdid_list[2:3]:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev2:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " \
                              + str(content_ev2) + " in household " + str(householdid) \
                              + " is not in the BOOKED state"
                    assert False, message

            broadcasting_starttime = timeDiff(broadcasting_starttime)
            recordingstatechage = recordingstatecheck_timedelay + broadcasting_starttime
            print "Script will wait for " + str(recordingstatechage / 60) \
                  + " minutes to check the event recording state"
            time.sleep(recordingstatechage)
            print "Waiting additional %s seconds to workaround the state change issue." % (
                recording_delay)
            time.sleep(recording_delay)

            print "\n[STEP6]: Confirm EV1, EV2 is in recording state"
            for householdid in householdid_list[:2]:
                recordingcatalogresult, recordingcatalogresponse = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is " \
                              "not in the RECORDING state".format(content_ev1, householdid)
                    assert False, message

            for householdid in householdid_list[2:4]:
                recordingcatalogresult, recordingcatalogresponse = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is not in the RECORDING state".format(
                        content_ev2, householdid)
                    assert False, message

            print "\n[STEP7]: Confirming that all households, recording its content with copy type as unique."

            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev1],
                                                       householdid_list[:2],
                                                       timeout)
            print "Playback URI list :", playbackuri_list
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            print "ContentId list :", contentidlist
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            riodev_recording_hh1 = json.loads(vmr_response_1.content)[0]
            riodev_recording_hh2 = json.loads(vmr_response_2.content)[0]
            assert riodev_recording_hh1["CopyType"] == copy_type and riodev_recording_hh2["CopyType"] == copy_type, \
                "Testcase Failed: Content %s are not in expected copy type %s in household 1 & household 2." \
                % (content_ev1, copy_type)

            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev2],
                                                       householdid_list[2:4],
                                                       timeout)
            print "Playback URI list :", playbackuri_list
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            riodev_recording_hh3 = json.loads(vmr_response_1.content)[0]
            riodev_recording_hh4 = json.loads(vmr_response_2.content)[0]
            assert riodev_recording_hh3["CopyType"] == copy_type and riodev_recording_hh4["CopyType"] == copy_type, \
                "Testcase Failed: Content %s are not in expected copy type %s in " \
                "household 3 and household 4." % (content_ev2, copy_type)

            print "\n[STEP8] : Change the SRT to Common Copy"
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_common_content)
            print "SRT load time wait: 20 seconds."

            print "\n[STEP9]: Book UC EV3 from HH1, HH2 on CH1 and UC EV4 from HH3, HH4 on CH2"
            for householdid in householdid_list[:2]:
                result = do_PPSbooking(pps_port, protocol, pps_host,
                                       householdid, pps_headers, payload_ev3,
                                       content_ev3, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev3) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            for householdid in householdid_list[2:4]:
                result = do_PPSbooking(pps_port, protocol, pps_host,
                                       householdid, pps_headers, payload_ev4,
                                       content_ev4, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev4) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            time.sleep(20)
            print "\n[STEP10] : Rename the SRT file"
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.rename_srt_file(cfg, "srt")

            print "\n[STEP11]: Confirm EV1, EV2 is in booked state"

            time.sleep(fetch_bookingcatalog_delay)
            # Getting Catalog Response for the Booked Catalog
            for householdid in householdid_list[:2]:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev3,
                    timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev3:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " + str(content_ev3) + " in household " \
                              + str(householdid) + " is not in the BOOKED state"
                    assert False, message

            for householdid in householdid_list[2:3]:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev4,
                    timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev4:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " + str(content_ev4) + " in household " + str(householdid) \
                              + " is not in the BOOKED state"
                    assert False, message

            broadcasting_starttime = timeDiff(broadcasting_starttime)
            recordingstatechage = recordingstatecheck_timedelay + broadcasting_starttime
            print "Script will wait for " + str(recordingstatechage / 60) \
                  + " minutes to check the event recording state"
            time.sleep(recordingstatechage)
            print "Waiting additional %s seconds to workaround the state change issue." % recording_delay
            time.sleep(recording_delay)

            print "\n[STEP12]: Confirm EV1, EV2 is in recording state"
            for householdid in householdid_list[:2]:
                recordingcatalogresult, recordingcatalogresponse = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev3,
                    timeout)
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is " \
                              "not in the RECORDING state".format(content_ev3, householdid)
                    assert False, message

            for householdid in householdid_list[2:4]:
                recordingcatalogresult, recordingcatalogresponse = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev4,
                    timeout)
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is not in the RECORDING state".format(
                        content_ev4, householdid)
                    assert False, message

            print "\n[STEP13]: Verify 2 Common copies present (1 per program)"

            copy_type = common_copy
            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev3],
                                                       householdid_list[:2],
                                                       timeout)
            print "Playback URI list :", playbackuri_list
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            print "ContentId list :", contentidlist
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            riodev_recording_hh1 = json.loads(vmr_response_1.content)[0]
            riodev_recording_hh2 = json.loads(vmr_response_2.content)[0]
            assert riodev_recording_hh1["CopyType"] == copy_type and riodev_recording_hh2["CopyType"] == copy_type, \
                "Testcase Failed: Content %s are not in expected copy " \
                "type %s in household 1 & household 2." % (content_ev1, copy_type)

            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev4],
                                                       householdid_list[2:4],
                                                       timeout)
            print "Playback URI list :", playbackuri_list
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            riodev_recording_hh3 = json.loads(vmr_response_1.content)[0]
            riodev_recording_hh4 = json.loads(vmr_response_2.content)[0]
            assert riodev_recording_hh3["CopyType"] == copy_type and riodev_recording_hh4["CopyType"] == copy_type, \
                "Testcase Failed: Content %s are not in expected copy type %s in household 3 & " \
                "household 4." % (content_ev2, copy_type)
            message = "Testcase Passed: All the recordings are present in the expected copy type " \
                      "(common - last known SRT before renaming.)"
            tims_dict = update_tims_data(tims_dict, 0, message, [test_id])

        except AssertionError as ae:
            message = str(ae)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        except Exception as e:
            message = str(e)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        finally:
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host,
                                  householdid, pps_headers, timeout)
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content_reset)
            print message
            return tims_dict
def doit_wrapper(cfg, printflg=False):
    message = ""
    status = 3
    test_id = "TC10120"
    tims_dict = {test_id: ["US78110", message, status]}
    print "%s: BRB - Dual VMR - Redirect recording before scheduling to different VMR " \
          "for different channels with different copy type in SRT." % (test_id)

    try:
        # announce
        # abspath = os.path.abspath(__file__)
        scriptName = os.path.basename(__file__)
        (test, ext) = os.path.splitext(scriptName)
        print "Starting test " + test

        if "no_brb" in cfg["test-flags"]:
            message = "Testcase Skipped: Skipping the testcases since no_brb flag is enabled."
            print message
            tims_dict = update_tims_data(tims_dict, 2, message, [test_id])
            return tims_dict

        # Initialize the Variables
        timeout = 2
        serviceIdlist = []

        # set values based on config
        cmdc_hosts = [cfg['cmdc']['host']]
        pps_hosts = [cfg['pps']['host']]
        upm_hosts = [cfg['upm']['host']]
        cmdc_port = cfg['cmdc']['port']
        pps_port = cfg['pps']['port']
        catalogueId = cfg['catalogueId']
        protocol = cfg['protocol']
        region = cfg['region']

        # Handle if the there are less channels than the threshold.
        threshold_channels = 17
        channelfilter1 = []
        for channels in cfg['test_channels'].keys():
            if channels.startswith("GenericCh"):
                channelfilter1.append(channels)
        if len(channelfilter1) < threshold_channels:
            message = "Skipping this TC since number of channels are less than 17."
            print message
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
            return tims_dict

        # Hardcoded the channel due to UUID channel issue while routing and recording.
        ch1 = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "channels"][0]
        ch2 = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "channels"][1]
        ch3 = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "channels"][2]
        ch4 = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "channels"][3]
        ch5 = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "channels"][4]
        testchannel1 = cfg['test_channels'][ch1]['ServiceId']
        testchannel2 = cfg['test_channels'][ch2]['ServiceId']
        testchannel3 = cfg['test_channels'][ch3]['ServiceId']
        testchannel4 = cfg['test_channels'][ch4]['ServiceId']
        testchannel5 = cfg['test_channels'][ch5]['ServiceId']

        serviceIdlist.append(unicode(testchannel1))
        serviceIdlist.append(unicode(testchannel2))
        serviceIdlist.append(unicode(testchannel3))
        serviceIdlist.append(unicode(testchannel4))
        serviceIdlist.append(unicode(testchannel5))

        prefix = cfg['basic_feature']['household_prefix']
        fetch_bookingcatalog_delay = cfg['pps']['fetch_bookingCatalog_delay']
        recordingstatecheck_timedelay = cfg['pps']['booked_to_recording_delay']
        recording_to_recorded_delay = cfg['pps']['recording_to_recorded_delay']
        householdid1 = prefix + '0'
        householdid2 = prefix + '1'
        householdid3 = prefix + '2'
        householdid4 = prefix + '3'
        householdid5 = prefix + '4'
        householdid_list = [
            householdid1, householdid2, householdid3, householdid4,
            householdid5
        ]
        hostlist = list(itertools.product(cmdc_hosts, pps_hosts, upm_hosts))
        broadcasting_starttime = 0
        broadcasting_endtime = 0
        recording_delay = 60
        common_copy = "COMMON"
        unique_copy = "UNIQUE"
        source_region = cfg["feature"]["brb"]["Recorderegions"]["v2pcVMR"][
            "name"]
        dest_region = cfg["feature"]["brb"]["Recorderegions"]["standaloneVMR"][
            "name"]
        invalid_region = "Invalid"
        copy_type = unique_copy
        ingest_delay = 120
        vmr = cfg['feature']['brb']['Recorderregions']['v2pcVMR']['host']
        aws_vmr = cfg['feature']['brb']['Recorderregions']['standaloneVMR'][
            'host']
        print "VMR : ", vmr
        print "AWS_VMR :", aws_vmr

        region_index = 5
        contentURI_list = []

        srt_content = [
            [source_region,
             str(testchannel1), dest_region, common_copy],
            [source_region,
             str(testchannel2), dest_region, unique_copy],
            [source_region,
             str(testchannel3), invalid_region, common_copy],
            [source_region,
             str(testchannel4), dest_region, common_copy],
            [source_region,
             str(testchannel5), dest_region, unique_copy]
        ]

        srt_content_reset = [[source_region, "*", source_region, "NoChange"]]

        # Do PPS Booking
        pps_headers = {
            'Content-Type': 'application/json',
            'Source-Type': 'WEB',
            'Source-ID': '127.0.0.1',
        }

        ###########################  USER DEFINED POST TIME IN UTC ############################
        start_delay = 5
        timeslotinminutes = cfg["test_channels"]["mediumProgramLength"] * 2
        ingestion_time = get_utc_time_after_n_minutes(start_delay, True)
        start_time = datetime.datetime.strptime(ingestion_time,
                                                '%Y-%m-%dT%H:%M:%S')
        post_time = calendar.timegm(start_time.timetuple()) + 0.0001
        #######################################################################################

        print "### STEP1: Ingest an event of n minutes with the " \
              "posttime of n Minutes to the CI Host ######## \n \n"
        ci_host = cfg['ci']['host']
        ci_port = cfg['ci']['port']
        ingest_minimum_delay = cfg['ci']['ingest_minimum_delay']
        ingest_delay_factor_per_minute = cfg['ci'][
            'ingest_delay_factor_per_minute']

        eventtitle1 = test_id + str(random.randint(1, 499))

        channel1 = ChannelLineup(BoundaryInMinutes=0)
        channel1.add_to_lineup(serviceId=testchannel1,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=1,
                               programIDPrefix=eventtitle1)
        channel1.postXmlData(ci_host, ci_port, startTime=post_time)
        channel1.writeXmlFiles(startTime=post_time)

        print "channel1 : ", channel1

        channel2 = ChannelLineup(BoundaryInMinutes=0)
        channel2.add_to_lineup(serviceId=testchannel2, \
                               timeSlotLengthMinutes=timeslotinminutes, timeSlotCount=1, \
                               programIDPrefix=eventtitle1)
        channel2.postXmlData(ci_host, ci_port, startTime=post_time)
        channel2.writeXmlFiles(startTime=post_time)

        print "channel2 : ", channel2

        channel3 = ChannelLineup(BoundaryInMinutes=0)
        channel3.add_to_lineup(serviceId=testchannel3, \
                               timeSlotLengthMinutes=timeslotinminutes, timeSlotCount=1, \
                               programIDPrefix=eventtitle1)
        channel3.postXmlData(ci_host, ci_port, startTime=post_time)
        channel3.writeXmlFiles(startTime=post_time)

        print "channel3 : ", channel3

        channel4 = ChannelLineup(BoundaryInMinutes=0)
        channel4.add_to_lineup(serviceId=testchannel4, \
                               timeSlotLengthMinutes=timeslotinminutes, timeSlotCount=1, \
                               programIDPrefix=eventtitle1)
        channel4.postXmlData(ci_host, ci_port, startTime=post_time)
        channel4.writeXmlFiles(startTime=post_time)

        print "channel4 : ", channel4

        channel5 = ChannelLineup(BoundaryInMinutes=0)
        channel5.add_to_lineup(serviceId=testchannel5, \
                               timeSlotLengthMinutes=timeslotinminutes, timeSlotCount=1, \
                               programIDPrefix=eventtitle1)
        channel5.postXmlData(ci_host, ci_port, startTime=post_time)
        channel5.writeXmlFiles(startTime=post_time)

        print "channel5 : ", channel5

        print "Wait time for the catalog ingest to " \
              "get synced with the CI Host in seconds: " + str(ingest_delay)
        time.sleep(ingest_delay)

    except:
        message = "Testcase Failed: Error Occurred in Configuration " + PrintException(
            True)
        print message
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
        return tims_dict

    for (cmdc_host, pps_host, upm_host) in hostlist:
        try:

            print "Ensure four household present in the system pointing to " \
                  "RR1 recording region. ###\n"
            for household in householdid_list:
                hh_region = get_household_region(cfg, upm_host, household,
                                                 timeout)
                assert hh_region == source_region, "Testcase Fail : Household %s not in the " \
                                                   "source region %s" % (household, source_region)

            print "### STEP2. Modify the SRT in such a way to record the contents as below,"
            print "           RR1|Ch1|RR2|Common"
            print "           RR1|Ch2|RR2|Unique"
            print "           RR1|Ch3|INVALID RR|Common"
            print "           RR1|Ch4|RR2|Common"
            print "           RR1|Ch5|RR2|Unique ###### \n"
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.set_srt_availability(cfg, state="Enable")
            configureSRT_instance.modify_srt(cfg, srt_content)

            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host, \
                                  householdid, pps_headers, timeout)

            gridservicelistresponse = fetch_gridRequest(catalogueId, protocol, cmdc_host, cmdc_port, \
                                                        serviceIdlist, region, timeout, printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(gridservicelistresponse, \
                                                           eventtitle1, ['title'])
            print "ContentID dictionary from the Grid Response\n" + str(
                contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable to Form ContentId " \
                                       "dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (len(contentId_list) > 0), "Testcase Failed: Unable to form ContentId " \
                                              "list from ContentId dictionary"

            content_ev1 = contentId_list[0][0]
            content_ev2 = contentId_list[1][0]
            content_ev3 = contentId_list[2][0]
            content_ev4 = contentId_list[3][0]
            content_ev5 = contentId_list[4][0]

            household_content_list = []
            for householdid, content_evt in zip(householdid_list,
                                                contentId_list):
                content_evt = list(content_evt)
                payload_evt = """{
                                "scheduleInstanceId" : "%s",
                                "checkConflicts" : true,
                                "pvr":"nPVR"
                                }""" % (content_evt[0])
                household_content_list.append(
                    [householdid, content_evt[0], payload_evt])

            print "### STEP3. Perform booking for the ingested contents as below."
            print "           Perform an booking for the contents from channel 1 from hh1."
            print "           Perform an booking for the contents from channel 2 from hh2."
            print "           Perform an booking for the contents from channel 3 from hh3."
            print "           Perform an booking for the contents from channel 4 from hh4."
            print "           Perform an booking for the contents from channel 5 from hh5.### \n"
            for householdid, content_ev, payload_ev in household_content_list:
                result = do_PPSbooking(pps_port, protocol, pps_host, householdid, \
                                       pps_headers, payload_ev, content_ev, timeout, printflg)
                assert result == "PASS", "Testcase Failed:Unable to do pps booking of content ID " \
                                         + str(content_ev) + " in household " + str(householdid)

            print "### STEP4: Wait for the program to start its recording on all " \
                  "four households. ##### \n \n"
            time.sleep(fetch_bookingcatalog_delay)
            # Getting Catalog Response for the Booked Catalog
            for (householdid, content_ev,
                 payload_ev) in household_content_list:
                catalogresult, catalogresponse = verify_booking(pps_port, protocol, pps_host, \
                                                                householdid, content_ev, timeout)
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " + str(content_ev) + " in household " \
                              + str(householdid) + " is not in the BOOKED state"
                    assert False, message

            broadcasting_starttime = timeDiff(broadcasting_starttime)
            print "broadcasting_starttime :", broadcasting_starttime
            recordingstatechage = recordingstatecheck_timedelay + broadcasting_starttime
            print "Script will wait for " + str(recordingstatechage / 60) \
                  + " minutes to check the event recording state"
            time.sleep(recordingstatechage)
            print "Waiting additional %s seconds to workaround the " \
                  "state change issue." % (recording_delay)
            time.sleep(recording_delay)

            print "### STEP5: Confirm that except hh3 all hhs contents are in recording state." \
                  "Also confirm that hh1, hh2, hh4, hh5 has its content recording as " \
                  "per the rule specified in SRT.##### \n \n"

            for householdid, content_ev, payload_ev in household_content_list:
                recrding_res, recrding_resp = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev,
                    timeout)
                if recrding_res != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is " \
                              "not in the RECORDING state".format(content_ev, householdid)
                    assert False, message

            cfg['vmr']['host'] = aws_vmr
            copy_type_list = []
            region_list = []
            for householdid, content_ev, payload_ev in household_content_list:
                if householdid == householdid3:
                    continue
                playbackuri_list = get_content_playbackURI(pps_host, pps_port, protocol, [content_ev], \
                                                       [householdid], timeout)
                assert playbackuri_list is not None, "TestCase failed: Unable to get recording catalog"
                print "Playback URI list :", playbackuri_list
                contentidlist = get_contentid_from_recid(
                    cfg, playbackuri_list, timeout)
                print "ContentId list :", contentidlist
                vmr_response = get_vmr_response(cfg, contentidlist[0], timeout)
                recording_hh = json.loads(vmr_response.content)[0]
                copy_type_hh = recording_hh["CopyType"]
                region_hh = recording_hh['A8UpdateURL'].split(
                    '/')[region_index]
                copy_type_list.append(copy_type_hh)
                region_list.append(region_hh)

            assert copy_type_list[0] == copy_type_list[3] == common_copy, \
                "Testcase Failed: Contents are not in expected copy " \
                "type %s in household 1 and 4."
            assert copy_type_list[1] == copy_type_list[4] == unique_copy, \
                "Testcase Failed: Contents are not in expected copy " \
                "type %s in household 2 and 5."

            assert region_list[0] == region_list[1] == region_list[3] == region_list[4] == dest_region, \
                "Testcase Failed: Contents are not in expected region " \
                " %s in household 3 and 4." % (dest_region)

            message = "Testcase Passed: SRT is working as expected."

        except AssertionError as ae:
            message = str(ae)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        except Exception as e:
            message = str(e)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        finally:
            print "STEP7. Cleanup the households and srt table."
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host, \
                                  householdid, pps_headers, timeout)
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content_reset)
            print message
            return tims_dict
Example #11
0
def doit_wrapper(cfg, printflg=False):
    """
    Entrypoint routine for the TC.
    """
    message = ""
    status = 3
    test_id = "TC9586"
    tims_dict = {test_id: ["US79250", message, status]}
    print "%s: Big Red Button - static_routing_table.txt file " \
           "edited before event SCHEDULE and event RECORD." % (test_id)
    try:
        # announce
        #abspath = os.path.abspath(__file__)
        scriptName = os.path.basename(__file__)
        (test, ext) = os.path.splitext(scriptName)
        print "Starting test " + test

        if "no_brb" in cfg["test-flags"]:
            message = "Testcase Skipped: Skipping the testcases since no_brb flag is enabled."
            print message
            tims_dict = update_tims_data(tims_dict, 3, message, [test_id])
            return tims_dict

        # Initialize the Variables
        timeout = 2
        serviceIdlist = []

        # set values based on config
        cmdc_hosts = [cfg['cmdc']['host']]
        pps_hosts = [cfg['pps']['host']]
        cmdc_port = cfg['cmdc']['port']
        pps_port = cfg['pps']['port']
        catalogueId = cfg['catalogueId']
        protocol = cfg['protocol']
        region = cfg['region']
        testchannel1 = cfg['test_channels']['GenericCh1']['ServiceId']
        testchannel2 = cfg['test_channels']['GenericCh2']['ServiceId']
        testchannel3 = cfg['test_channels']['GenericCh3']['ServiceId']
        serviceIdlist.append(unicode(testchannel1))
        serviceIdlist.append(unicode(testchannel2))
        serviceIdlist.append(unicode(testchannel3))
        prefix = cfg['basic_feature']['household_prefix']
        fetch_bookingcatalog_delay = cfg['pps']['fetch_bookingCatalog_delay']
        recordingstatecheck_timedelay = cfg['pps']['booked_to_recording_delay']
        householdid1 = prefix + '1'
        householdid2 = prefix + '2'
        householdid3 = prefix + '3'
        householdid4 = prefix + '4'
        householdid_list = [
            householdid1, householdid2, householdid3, householdid4
        ]
        hostlist = list(itertools.product(cmdc_hosts, pps_hosts))

        recording_delay = 60
        ingestion_delay = 120
        common_copy = "COMMON"
        unique_copy = "UNIQUE"
        source_region = cfg["recorderRegion"]
        dest_region = cfg["recorderRegion"]
        srt_content = [[source_region, "*", dest_region, "common"]]
        srt_content_reset = [
            [source_region, "*", dest_region, "NoChange"],
        ]

        # Do PPS Booking
        pps_headers = {
            'Content-Type': 'application/json',
            'Source-Type': 'WEB',
            'Source-ID': '127.0.0.1',
        }

        ###########################  USER DEFINED POST TIME IN UTC ############
        start_delay = 5
        # Duration of the event is more than 20 minutes.This dusration is to avoid
        # the pps to send the schedule request for the event 2 which in turn will
        # help to test the BRB.
        timeslotinminutes = cfg["test_channels"]["longProgramLength"] * 5
        ingestion_time = get_utc_time_after_n_minutes(start_delay, True)
        start_time = datetime.datetime.strptime(ingestion_time,
                                                '%Y-%m-%dT%H:%M:%S')
        post_time = calendar.timegm(start_time.timetuple()) + 0.0001
        #######################################################################

        print "### STEP1: Ingest an event of n minutes with the " \
              "posttime of n Minutes to the CI Host ######## \n \n"
        ci_host = cfg['ci']['host']
        ci_port = cfg['ci']['port']
        #ingest_minimum_delay = cfg['ci']['ingest_minimum_delay']
        #ingest_delay_factor_per_minute = cfg['ci']['ingest_delay_factor_per_minute']

        eventtitle1 = "commoncp" + str(random.randint(1, 499))

        channel = ChannelLineup(BoundaryInMinutes=0)
        channel.add_to_lineup(serviceId=testchannel1,
                              timeSlotLengthMinutes=timeslotinminutes,
                              timeSlotCount=2,
                              programIDPrefix=eventtitle1)
        channel.postXmlData(ci_host, ci_port, startTime=post_time)
        channel.writeXmlFiles(startTime=post_time)
        #length = channel.getTotalLength()

        print "Wait time for the catalog ingest to "\
        "get synced with the CI Host in seconds: " + str(ingestion_delay)
        time.sleep(ingestion_delay)

    except BaseException:
        message = "Testcase Failed: Error Occurred in Configuration " + \
            PrintException(True)
        print message
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
        return tims_dict

    for (cmdc_host, pps_host) in hostlist:
        try:

            # Cleanup HH
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host,
                                  householdid, pps_headers, timeout)
            # Setting the SRT table in such a way to record the contents with Unique copy type.
            #configureSRT_instance = ConfigureSRT()
            #configureSRT_instance.modify_srt(cfg, [[source_region, "*", dest_region, "NoChange"]])

            print "### STEP2: Fetching the grid response "\
            "to collect the ingested content. ##### \n \n"
            gridservicelistresponse = fetch_gridRequest(
                catalogueId, protocol, cmdc_host, cmdc_port, serviceIdlist,
                region, timeout, printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(
                gridservicelistresponse, eventtitle1, ['title'])
            print "ContentID dictionary from the "\
            "Grid Response\n" + str(contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable to\
            Form ContentId dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (len(contentId_list) > 0), "Testcase Failed: Unable "\
                       "to form ContentId list from ContentId dictionary"

            content_ev1 = contentId_list[0][0]
            content_ev2 = contentId_list[1][0]

            payload_ev1 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev1)

            payload_ev2 = """{
                            "scheduleInstanceId" : "%s",
                            "checkConflicts" : true,
                            "pvr":"nPVR"
                            }""" % (content_ev2)

            print "About to start the event 1 booking\n\n"
            print "### STEP3: PPS event-1 booking is "\
            "being done for all four households. ##### \n \n"
            for householdid in householdid_list:
                result = do_PPSbooking(pps_port, protocol, pps_host,
                                       householdid, pps_headers, payload_ev1,
                                       content_ev1, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " + \
                        str(content_ev1) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 ["TC1699"])
            print "PPS Booking is successful for the event "\
            "contentid ", content_ev1, " on all 4 households"

            print "About to start the event 2 booking on all the four households\n\n"
            print "### STEP4: PPS event-2 booking is being done for all four households. ### \n \n"
            for householdid in householdid_list:
                result = do_PPSbooking(pps_port, protocol, pps_host,
                                       householdid, pps_headers, payload_ev2,
                                       content_ev2, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " + \
                        str(content_ev2) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 ["TC1699"])
            print "PPS Booking is successful for the "\
            "event contentid ", content_ev2, " on all 4 households"
            print "### STEP5: Confirming that all four households "\
            "has the booked item-1 in booked state. ### \n \n"
            time.sleep(fetch_bookingcatalog_delay)
            broadcasting_starttime = 0
            #broadcasting_endtime = 0
            # Getting Catalog Response for the Booked Catalog
            for householdid in householdid_list:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev1:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                #broadcasting_endtime = items['content']['endAvailability']
                        except BaseException:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " + \
                        str(content_ev1) + " in household " + \
                        str(householdid) + " is not in the BOOKED state"
                    assert False, message

            print "#### STEP6: Confirming that all four households has "\
            "the booked item-2 in booked state. ##### \n \n"
            broadcasting_starttime1 = 0
            #broadcasting_endtime1 = 0
            # Getting Catalog Response for the Booked Catalog
            for householdid in householdid_list:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev2:
                                broadcasting_starttime1 = items['content'][
                                    'broadcastDateTime']
                                #broadcasting_endtime1 = items['content']['endAvailability']
                        except BaseException:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " + \
                        str(content_ev2) + " in household " + \
                        str(householdid) + " is not in the BOOKED state"
                    assert False, message

            recordingstatechage = recordingstatecheck_timedelay + \
                timeDiff(broadcasting_starttime)
            print "Script will wait for " + str(recordingstatechage / 60) + \
                " minutes to check the event recording state"
            time.sleep(recordingstatechage)
            print "Waiting additional %s seconds to workaround "\
            "the recording state change issue." % (recording_delay)
            time.sleep(recording_delay)

            print "### STEP7: Changing the SRT file in such a way that "\
            "to record the upcoming contents with common copy type. ##### \n \n"
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content)

            print "### STEP8: Confirming that all four households has the "\
            "booked item-1 in recording state. ##### \n \n"
            for householdid in householdid_list:
                recordingcatalogresult = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)[0]
                print "recordingcatalogresult : ", recordingcatalogresult
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in "\
                    "household {1} is not in the RECORDING state".format(
                        content_ev1, householdid)
                    assert False, message

            print "### STEP9: Confirming that all households, "\
            "recording its content-1 with copy type as unique. ##### \n \n"
            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev1],
                                                       householdid_list,
                                                       timeout)
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)

            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            vmr_response_3 = get_vmr_response(cfg, contentidlist[2], timeout)
            vmr_response_4 = get_vmr_response(cfg, contentidlist[3], timeout)

            riodev_recording_hh1 = json.loads(vmr_response_1.content)[0]
            riodev_recording_hh2 = json.loads(vmr_response_2.content)[0]
            riodev_recording_hh3 = json.loads(vmr_response_3.content)[0]
            riodev_recording_hh4 = json.loads(vmr_response_4.content)[0]

            assert riodev_recording_hh1["CopyType"] == unique_copy and \
                riodev_recording_hh2["CopyType"] == unique_copy and \
                riodev_recording_hh3["CopyType"] == unique_copy and \
                riodev_recording_hh4["CopyType"] == unique_copy, \
                "Testcase Failed: Contents are not in unique copy in some households."
            print "Contents are getting recorded in unique copy in all households."

            print "### STEP10: Confirming that all four households "\
            "has the booked item-2 in recording state. ##### \n \n"
            recordingstatechage = recordingstatecheck_timedelay + \
                timeDiff(broadcasting_starttime1)
            print "Script will wait for " + str(recordingstatechage / 60)\
                + " minutes to check the event recording state"
            time.sleep(recordingstatechage)

            for householdid in householdid_list:
                recordingcatalogresult = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)[0]
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in "\
                    "household {1} is not in the RECORDING state".format(
                        content_ev2, householdid)
                    assert False, message

            print "### STEP11: Confirming that all households, recording "\
            "its content-2 with copy type as common. ##### \n \n"
            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev2],
                                                       householdid_list,
                                                       timeout)
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)

            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            vmr_response_3 = get_vmr_response(cfg, contentidlist[2], timeout)
            vmr_response_4 = get_vmr_response(cfg, contentidlist[3], timeout)

            riodev_recording_hh1 = json.loads(vmr_response_1.content)[0]
            riodev_recording_hh2 = json.loads(vmr_response_2.content)[0]
            riodev_recording_hh3 = json.loads(vmr_response_3.content)[0]
            riodev_recording_hh4 = json.loads(vmr_response_4.content)[0]

            assert riodev_recording_hh1["CopyType"] == common_copy \
                and riodev_recording_hh2["CopyType"] == common_copy\
                and riodev_recording_hh3["CopyType"] == common_copy\
                and riodev_recording_hh4["CopyType"] == common_copy,\
                "Testcase Failed: Contents are not in common copy in some households."
            print "Contents are getting recorded in common copy in all households."

            message = "TestCase Passed : SRT is working as expected for the "\
            "scenario of changing the copytype before between recording and scheduling."
            tims_dict = update_tims_data(tims_dict, 0, message, [test_id])

        except AssertionError as ae:
            message = str(ae)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        except Exception as e:
            message = str(e)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        finally:
            # Cleanup HH
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host,
                                  householdid, pps_headers, timeout)
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content_reset)
            print message
            return tims_dict
Example #12
0
def doit_wrapper(cfg, printflg=False):

    message = ""
    status = 3
    test_id = "TC9840"
    tims_dict = {test_id: ["US80598", message, status]}
    print "%s: Big Red Button - SRT with UC, CC and NoChange for 3 channels." % test_id

    try:
        # announce
        # abspath = os.path.abspath(__file__)
        scriptName = os.path.basename(__file__)
        (test, ext) = os.path.splitext(scriptName)
        print "Starting test " + test

        if "no_brb" in cfg["test-flags"]:
            message = "Testcase Skipped: Skipping the testcases since no_brb flag is enabled."
            print message
            tims_dict = update_tims_data(tims_dict, 2, message, [test_id])
            return tims_dict

        # Initialize the Variables
        timeout = 2
        serviceIdlist = []

        # set values based on config
        cmdc_hosts = [cfg['cmdc']['host']]
        pps_hosts = [cfg['pps']['host']]
        cmdc_port = cfg['cmdc']['port']
        pps_port = cfg['pps']['port']
        catalogueId = cfg['catalogueId']
        protocol = cfg['protocol']
        region = cfg['region']

        testchannel1 = cfg['test_channels']['GenericCh1']['ServiceId']
        testchannel2 = cfg['test_channels']['GenericCh2']['ServiceId']
        testchannel3 = cfg['test_channels']['GenericCh3']['ServiceId']

        serviceIdlist.append(unicode(testchannel1))
        serviceIdlist.append(unicode(testchannel2))
        serviceIdlist.append(unicode(testchannel3))

        prefix = cfg['feature']['household_prefix']
        fetch_bookingcatalog_delay = cfg['pps']['fetch_bookingCatalog_delay']
        recordingstatecheck_timedelay = cfg['pps']['booked_to_recording_delay']
        householdid1 = prefix + '1'
        householdid2 = prefix + '2'
        householdid3 = prefix + '3'
        householdid4 = prefix + '4'
        householdid_list = [
            householdid1, householdid2, householdid3, householdid4
        ]
        hostlist = list(itertools.product(cmdc_hosts, pps_hosts))
        broadcasting_starttime = 0
        broadcasting_endtime = 0
        recording_delay = 60
        common_copy = "COMMON"
        unique_copy = "UNIQUE"
        source_region = cfg["recorderRegion"]
        dest_region = cfg["recorderRegion"]
        copy_type = unique_copy
        ingest_delay = 150

        srt_content = [
            [source_region,
             str(testchannel1), dest_region, "unique"],
            [source_region,
             str(testchannel2), dest_region, "common"],
            [source_region,
             str(testchannel3), dest_region, "NoChange"]
        ]
        srt_content_reset = [[source_region, "*", dest_region, "NoChange"]]
        copy_index_srt = 3
        channel_index_srt = 1
        map_copy_type = {}

        # Do PPS Booking
        pps_headers = {
            'Content-Type': 'application/json',
            'Source-Type': 'WEB',
            'Source-ID': '127.0.0.1',
        }

        ###########################  USER DEFINED POST TIME IN UTC ############################
        start_delay = 5
        timeslotinminutes = cfg["test_channels"]["longProgramLength"] * 2
        ingestion_time = get_utc_time_after_n_minutes(start_delay, True)
        start_time = datetime.datetime.strptime(ingestion_time,
                                                '%Y-%m-%dT%H:%M:%S')
        post_time = calendar.timegm(start_time.timetuple()) + 0.0001
        #######################################################################################

        print "\n[STEP1]: Ingest 1 event of n minutes in 3 channels with the posttime of n Minutes to the CI Host"
        ci_host = cfg['ci']['host']
        ci_port = cfg['ci']['port']
        ingest_minimum_delay = cfg['ci']['ingest_minimum_delay']
        ingest_delay_factor_per_minute = cfg['ci'][
            'ingest_delay_factor_per_minute']

        eventtitle1 = "uniquecp" + str(random.randint(1, 499))

        channel1 = ChannelLineup(BoundaryInMinutes=0)
        channel1.add_to_lineup(serviceId=testchannel1,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=1,
                               programIDPrefix=eventtitle1)
        channel1.postXmlData(ci_host, ci_port, startTime=post_time)
        channel1.writeXmlFiles(startTime=post_time)

        print "channel1 : ", channel1

        channel2 = ChannelLineup(BoundaryInMinutes=0)
        channel2.add_to_lineup(serviceId=testchannel2,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=1,
                               programIDPrefix=eventtitle1)
        channel2.postXmlData(ci_host, ci_port, startTime=post_time)
        channel2.writeXmlFiles(startTime=post_time)

        print "channel2 : ", channel2

        channel3 = ChannelLineup(BoundaryInMinutes=0)
        channel3.add_to_lineup(serviceId=testchannel3,
                               timeSlotLengthMinutes=timeslotinminutes,
                               timeSlotCount=1,
                               programIDPrefix=eventtitle1)
        channel3.postXmlData(ci_host, ci_port, startTime=post_time)
        channel3.writeXmlFiles(startTime=post_time)

        print "channel3 : ", channel3

        print "Wait time for the catalog ingest to get synced with the CI Host in seconds: " + str(
            ingest_delay)
        time.sleep(ingest_delay)

    except:
        message = "Testcase Failed: Error Occurred in Configuration " + PrintException(
            True)
        print message
        tims_dict = update_tims_data(tims_dict, 1, message, [test_id])
        return tims_dict

    for (cmdc_host, pps_host) in hostlist:
        try:
            print "\n[STEP2]: Setting the SRT table in such a way to record the contents with UC for " \
                  "channel-1 and CC for channel-2 and NoChange for channel-3"
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content)

            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host,
                                  householdid, pps_headers, timeout)

            print "\n[STEP3]: Fetching the grid response to collect the ingested content."
            gridservicelistresponse = fetch_gridRequest(
                catalogueId, protocol, cmdc_host, cmdc_port, serviceIdlist,
                region, timeout, printflg)
            assert gridservicelistresponse, "Testcase Failed: Unable to Fetch Grid Response"

            contentId_dict_all = get_contentIddict_bytitle(
                gridservicelistresponse, eventtitle1, ['title'])
            print "ContentID dictionary from the Grid Response\n" + str(
                contentId_dict_all)
            assert contentId_dict_all, "Testcase Failed: Unable to Form ContentId dictionary from the Grid Response"

            contentId_list = sorted(contentId_dict_all.items(),
                                    key=lambda x: x[1])
            print "ContentId list after Sorting\n" + str(contentId_list)
            assert (
                len(contentId_list) > 0
            ), "Testcase Failed: Unable to form ContentId list from ContentId dictionary"
            print "len(contentId_list) : ", len(contentId_list)

            content_ev1 = contentId_list[0][0]
            content_ev2 = contentId_list[1][0]
            content_ev3 = contentId_list[2][0]

            copy_type = [
                copy_type[copy_index_srt] for copy_type in srt_content
            ]
            chanel_map = [
                channel_map[channel_index_srt] for channel_map in srt_content
            ]
            for channel, copy_type in zip(chanel_map, copy_type):
                map_copy_type.update({channel: copy_type})

            print "map_copy_type : ", map_copy_type

            payload_ev1 = """{
                                "scheduleInstanceId" : "%s",
                                "checkConflicts" : true,
                                "pvr":"nPVR"
                                }""" % content_ev1

            payload_ev2 = """{
                                "scheduleInstanceId" : "%s",
                                "checkConflicts" : true,
                                "pvr":"nPVR"
                                }""" % content_ev2

            payload_ev3 = """{
                                "scheduleInstanceId" : "%s",
                                "checkConflicts" : true,
                                "pvr":"nPVR"
                                }""" % content_ev3

            print "About to start the event 1 booking\n\n"
            print "\n[STEP4]: PPS ch-1, event-1 on hh-1 and ch-2 event-1 on hh-2, hh-3 and ch-3 event-1 on hh-4 " \
                  "booking is being done for all 4 households."

            for householdid in householdid_list[:1]:
                result = do_PPSbooking(pps_port, protocol, pps_host,
                                       householdid, pps_headers, payload_ev1,
                                       content_ev1, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev1) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            for householdid in householdid_list[1:3]:
                result = do_PPSbooking(pps_port, protocol, pps_host,
                                       householdid, pps_headers, payload_ev2,
                                       content_ev2, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev1) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            for householdid in householdid_list[3:4]:
                result = do_PPSbooking(pps_port, protocol, pps_host,
                                       householdid, pps_headers, payload_ev3,
                                       content_ev3, timeout, printflg)
                if result != "PASS":
                    message = "Testcase Failed:Unable to do pps booking of content ID " \
                              + str(content_ev1) + " in household " + str(householdid)
                    print message
                    tims_dict = update_tims_data(tims_dict, 1, message,
                                                 [test_id])

            print "\n[STEP5]: Confirming that all four households has the booked item-1 in booked state"

            time.sleep(fetch_bookingcatalog_delay)
            # Getting Catalog Response for the Booked Catalog
            for householdid in householdid_list[:1]:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev1:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " + str(content_ev1) + " in household " \
                              + str(householdid) + " is not in the BOOKED state"
                    assert False, message

            for householdid in householdid_list[1:3]:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev2:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " \
                              + str(content_ev2) + " in household " + str(householdid) \
                              + " is not in the BOOKED state"
                    assert False, message

            for householdid in householdid_list[3:4]:
                catalogresult, catalogresponse = verify_booking(
                    pps_port, protocol, pps_host, householdid, content_ev3,
                    timeout)
                print "Booking response :", catalogresult
                if catalogresult == "PASS":
                    jsonresponse = json.loads(catalogresponse.content)
                    for items in jsonresponse:
                        try:
                            if items['scheduleInstance'] == content_ev3:
                                broadcasting_starttime = items['content'][
                                    'broadcastDateTime']
                                broadcasting_endtime = items['content'][
                                    'endAvailability']
                        except:
                            pass
                else:
                    message = "TestCase  Failed : Content ID " \
                              + str(content_ev3) + " in household " + str(householdid) \
                              + " is not in the BOOKED state"
                    assert False, message

            broadcasting_starttime = timeDiff(broadcasting_starttime)
            recordingstatechage = recordingstatecheck_timedelay + broadcasting_starttime
            print "Script will wait for " + str(recordingstatechage / 60) \
                  + " minutes to check the event recording state"
            time.sleep(recordingstatechage)
            print "Waiting additional %s seconds to workaround the state change issue." % recording_delay
            time.sleep(recording_delay)

            print "\n[STEP6]: Confirming that all households has the booked items in recording state"
            for householdid in householdid_list[:1]:
                recordingcatalogresult, recordingcatalogresponse = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev1,
                    timeout)
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is " \
                              "not in the RECORDING state".format(content_ev1, householdid)
                    assert False, message

            for householdid in householdid_list[1:3]:
                recordingcatalogresult, recordingcatalogresponse = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev2,
                    timeout)
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is not in the RECORDING state".format(
                        content_ev2, householdid)
                    assert False, message

            for householdid in householdid_list[3:4]:
                recordingcatalogresult, recordingcatalogresponse = verify_recording_state(
                    pps_port, protocol, pps_host, householdid, content_ev3,
                    timeout)
                if recordingcatalogresult != "PASS":
                    message = "Testcase Failed: Content ID {0} in household {1} is not in the RECORDING state".format(
                        content_ev3, householdid)
                    assert False, message

            print "\n[STEP7]: Confirming that the copy type of the recording in hh-1 is unique copy and hh-2 " \
                  "and hh-3 is common copy and hh-4 is unique copy"

            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev1],
                                                       householdid_list[:1],
                                                       timeout)
            print "Playback URI list :", playbackuri_list
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            print "ContentId list :", contentidlist
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            riodev_recording_hh1 = json.loads(vmr_response_1.content)[0]
            streamid = riodev_recording_hh1["StreamID"]
            if not isinstance(streamid, str):
                copy_type = map_copy_type[str(streamid)]
            else:
                copy_type = map_copy_type[streamid]
            if copy_type == "NoChange":
                copy_type = unique_copy
            copy_type = copy_type.upper()

            assert riodev_recording_hh1["CopyType"] == copy_type, \
                "Testcase Failed: Content %s are not in expected copy type %s in " \
                "household 1" % (content_ev1, copy_type)

            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev2],
                                                       householdid_list[1:3],
                                                       timeout)
            print "Playback URI list :", playbackuri_list
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            print "ContentId list :", contentidlist
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            vmr_response_2 = get_vmr_response(cfg, contentidlist[1], timeout)
            riodev_recording_hh2 = json.loads(vmr_response_1.content)[0]
            streamid = riodev_recording_hh2["StreamID"]
            if not isinstance(streamid, str):
                copy_type1 = map_copy_type[str(streamid)]
            else:
                copy_type1 = map_copy_type[streamid]
            if copy_type1 == "NoChange":
                copy_type1 = common_copy
            copy_type1 = copy_type1.upper()
            riodev_recording_hh3 = json.loads(vmr_response_2.content)[0]
            streamid = riodev_recording_hh3["StreamID"]
            if not isinstance(streamid, str):
                copy_type2 = map_copy_type[str(streamid)]
            else:
                copy_type2 = map_copy_type[streamid]
            if copy_type2 == "NoChange":
                copy_type2 = common_copy
            copy_type2 = copy_type2.upper()
            assert riodev_recording_hh2["CopyType"] == copy_type1 and \
                   riodev_recording_hh3["CopyType"] == copy_type2, \
                "Testcase Failed: Content %s are not in expected copy " \
                "type %s in household 2 & household 3." % (content_ev2, common_copy)

            playbackuri_list = get_content_playbackURI(pps_host, pps_port,
                                                       protocol, [content_ev3],
                                                       householdid_list[3:4],
                                                       timeout)
            print "Playback URI list :", playbackuri_list
            contentidlist = get_contentid_from_recid(cfg, playbackuri_list,
                                                     timeout)
            print "ContentId list :", contentidlist
            vmr_response_1 = get_vmr_response(cfg, contentidlist[0], timeout)
            riodev_recording_hh4 = json.loads(vmr_response_1.content)[0]
            streamid = riodev_recording_hh4["StreamID"]
            if not isinstance(streamid, str):
                copy_type3 = map_copy_type[str(streamid)]
            else:
                copy_type3 = map_copy_type[streamid]
            if copy_type3 == "NoChange":
                copy_type3 = unique_copy
            copy_type3 = copy_type3.upper()
            assert riodev_recording_hh4["CopyType"] == copy_type3, \
                "Testcase Failed: Content %s are not in expected copy type %s in " \
                "household 4" % (content_ev1, copy_type3)
            message = "Testcase Passed: All the recordings are in expected copy type."
            tims_dict = update_tims_data(tims_dict, 0, message, [test_id])

        except AssertionError as ae:
            message = str(ae)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        except Exception as e:
            message = str(e)
            tims_dict = update_tims_data(tims_dict, 1, message, [test_id])

        finally:
            for householdid in householdid_list:
                cleanup_household(cfg, pps_port, protocol, pps_host,
                                  householdid, pps_headers, timeout)
            configureSRT_instance = ConfigureSRT()
            configureSRT_instance.modify_srt(cfg, srt_content_reset)
            print message
            return tims_dict