github.com/rancher/elemental/tests@v0.0.0-20240517125144-ae048c615b3f/cypress/latest/support/utils.ts (about)

     1  import * as cypressLib from '@rancher-ecp-qa/cypress-library';
     2  
     3  // Check the boot type
     4  export const isBootType = (bootType: string) => {
     5    return (new RegExp(bootType)).test(Cypress.env("boot_type"));
     6  }
     7  
     8  // Check the Cypress tags
     9  export const isCypressTag = (tag: string) => {
    10    return (new RegExp(tag)).test(Cypress.env("cypress_tags"));
    11  }
    12  
    13  // Check the K8s version
    14  export const isK8sVersion = (version: string) => {
    15    version = version.toLowerCase();
    16    return (new RegExp(version)).test(Cypress.env("k8s_downstream_version"));
    17  }
    18  
    19  // Check the Elemental operator version
    20  export const isOperatorVersion = (version: string) => {
    21    return (new RegExp(version)).test(Cypress.env("operator_repo"));
    22  }
    23  
    24  // Check rancher manager version
    25  export const isRancherManagerVersion = (version: string) => {
    26    return (new RegExp(version)).test(Cypress.env("rancher_version"));
    27  }
    28  
    29  // Check Elemental UI version
    30  export const isUIVersion = (version: string) => {
    31    return (new RegExp(version)).test(Cypress.env("elemental_ui_version"));
    32  }
    33  
    34  // Check the upgrade target
    35  export const isUpgradeOsChannel = (channel: string) => {
    36    return (new RegExp(channel)).test(Cypress.env("upgrade_os_channel"));
    37  }
    38  
    39  // Create Elemental cluster
    40  export const createCluster = (clusterName: string, k8sVersion: string, proxy: string) => {
    41    cy.getBySel('button-create-elemental-cluster')
    42      .click();
    43    cy.getBySel('name-ns-description-name')
    44      .type(clusterName);
    45    cy.getBySel('name-ns-description-description')
    46      .type('My Elemental testing cluster');
    47    cy.contains('.labeled-input.create', 'Machine Count')
    48      .clear()
    49    if (isCypressTag('main')) {
    50      cy.contains('.labeled-input.create', 'Machine Count')
    51        .type('3');
    52    } else {
    53      cy.contains('.labeled-input.create', 'Machine Count')
    54        .type('1');
    55    }
    56    cy.contains('Show deprecated Kubernetes')
    57      .click();
    58    cy.contains('Kubernetes Version')
    59      .click();
    60    cy.contains(k8sVersion)
    61      .click();
    62    // Configure proxy if proxy is set to elemental
    63    if (Cypress.env('proxy') == "elemental") {
    64      cy.contains('Agent Environment Vars')
    65        .click();
    66      cy.get('#agentEnv > .key-value')
    67        .contains('Add')
    68        .click();
    69      cy.getBySel('input-kv-item-key-0')
    70        .type('HTTP_PROXY');
    71      cy.getBySel('kv-item-value-0')
    72        .type(proxy);
    73      cy.get('#agentEnv > .key-value')
    74        .contains('Add')
    75        .click();
    76      cy.getBySel('input-kv-item-key-1')
    77        .type('HTTPS_PROXY');
    78      cy.getBySel('kv-item-value-1').type(proxy);
    79      cy.get('#agentEnv > .key-value')
    80        .contains('Add')
    81        .click();
    82      cy.getBySel('input-kv-item-key-2')
    83        .type('NO_PROXY');
    84      cy.getBySel('kv-item-value-2')
    85        .type('localhost,127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,.svc,.cluster.local');
    86      }
    87    cy.clickButton('Create');
    88    // This wait can be replaced by something cleaner
    89    // eslint-disable-next-line cypress/no-unnecessary-waiting
    90    cy.wait(3000);
    91    cypressLib.burgerMenuToggle();
    92    cypressLib.checkClusterStatus(clusterName, 'Updating', 300000);
    93    cypressLib.burgerMenuToggle();
    94    cypressLib.checkClusterStatus(clusterName, 'Active', 600000);
    95    // Ugly but needed unfortunately to make sure the cluster stops switching status
    96    // eslint-disable-next-line cypress/no-unnecessary-waiting
    97    cy.wait(240000);
    98  }