# Tcctl: a cli tool for test-infra

## Installation

```shell
curl http://fileserver.pingcap.net/download/pingcap/qa/test-infra/tcctl-install.sh | bash
```

## Usage

### Authenticate
1. visit https://tcms.pingcap.net/dashboard/settings/tokens , generate a token
2. tcctl config --token=\<your-token-from-step-1\> -r http://rms-staging.pingcap.net:30007

### Control the TCMS

Create a `test case`/`test plan`/`test trigger`:

1. Edit your `test case`/`test plan`/`test trigger` file, you can refer to [examples/cases.yaml](examples/cases.yaml)
2. Run `tcctl apply -f <your file here>`

Update a `test case`/`test plan`/`test trigger`:

1. Edit your `test case`/`test plan`/`test trigger` file, you can refer to [examples/plan.yaml](examples/plan.yaml)
2. Run `tcctl apply -f <your file here>`

Delete a `test case`/`test plan`/`test trigger`:

1. Run `tcctl delete -f <your file here>`

#### Run a one-shot plan

1. Edit a one-shot.yaml, you can refer to [examples/one-shot.yaml](examples/one-shot.yaml)
2. Run `tcctl run -f <your file here>`

Or one-shot run a [test-plan repo plan](https://github.com/pingcap/test-plan)
1. `tcctl run -f <your file here> -m <your meta.yaml file here>`

### Control the RMS

#### Create a testbed

1. Edit your testbed file, you can refer to [README](../../examples/README.md)
2. Run `tcctl testbed create -f \<your file here\>`, a `output` file will generate if succeed

Or:

1. Run `tcctl testbed create -i`, there will be a interative ui
2. Choose a proper template to submit, you can also edit the template before submit it.
3. Type 's' to submit, a `output` file will generate if succeed


#### Delete a testbed

Run `tcctl testbed delete testbed_xxx`.

Or:

Run `tcctl testbed delete -f output` under the directory where a `output` file generated.

#### List testbeds

Run `tcctl testbed list`

#### Renew a testbed

Every testbed has an expired time(the lease is 24 hours from the testbed was created). The User can use the tcctl to renew a testbed.

Run `tcctl testbed renew testbed_xxx` to renew the lease.

#### Debug a daily-run testbed

By default user doesn't have access right to daily-run testbeds. To access & debug the testbed, run `tcctl testbed auth testbed_xxx`, it will grant user basic privilege for debugging.

#### Restore TiDB Monitor from backuped prometheus data
Run `tcctl testbed restore-monitor <testbed>`. RMS will create a new testbed to restore the monitor of given testbed.

or `tcctl testbed restore-monitor --prom-tarball-url <prometheus-tarball-url>`, `<prometheus-tarball-url>` can be any valid tidb monitor backup, mostly the link is copied from MinIO.

#### Import cases from feishu sheets

1. Exporting sheets in csv.
2. Replace all of the Designer name with corresponding email address.
3. Run `tcctl apply -f cases.csv` to create the cases.
