2019-03-20 23:01:24 +01:00
|
|
|
package job
|
|
|
|
|
|
|
|
import (
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
"fmt"
|
2020-07-19 23:59:33 +02:00
|
|
|
"path"
|
|
|
|
"path/filepath"
|
2019-03-20 23:01:24 +01:00
|
|
|
"testing"
|
|
|
|
|
2020-07-19 23:59:33 +02:00
|
|
|
"github.com/kr/pretty"
|
2019-03-20 23:01:24 +01:00
|
|
|
"github.com/stretchr/testify/assert"
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/zrepl/zrepl/config"
|
2019-03-20 23:01:24 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestValidateReceivingSidesDoNotOverlap(t *testing.T) {
|
|
|
|
type testCase struct {
|
|
|
|
err bool
|
|
|
|
input []string
|
|
|
|
}
|
|
|
|
tcs := []testCase{
|
|
|
|
{false, nil},
|
|
|
|
{false, []string{}},
|
|
|
|
{false, []string{""}}, // not our job to determine valid paths
|
|
|
|
{false, []string{"a"}},
|
|
|
|
{false, []string{"some/path"}},
|
|
|
|
{false, []string{"zroot/sink1", "zroot/sink2", "zroot/sink3"}},
|
2020-01-30 01:59:57 +01:00
|
|
|
{false, []string{"zroot/foo", "zroot/foobar"}},
|
2019-03-20 23:01:24 +01:00
|
|
|
{true, []string{"zroot/b", "zroot/b"}},
|
|
|
|
{true, []string{"zroot/foo", "zroot/foo/bar", "zroot/baz"}},
|
|
|
|
{false, []string{"a/x", "b/x"}},
|
|
|
|
{false, []string{"a", "b"}},
|
|
|
|
{true, []string{"a", "a"}},
|
|
|
|
{true, []string{"a/x/y", "a/x"}},
|
|
|
|
{true, []string{"a/x", "a/x/y"}},
|
|
|
|
{true, []string{"a/x", "b/x", "a/x/y"}},
|
|
|
|
{true, []string{"a", "a/b", "a/c", "a/b"}},
|
|
|
|
{true, []string{"a/b", "a/c", "a/b", "a/d", "a/c"}},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range tcs {
|
|
|
|
t.Logf("input: %v", tc.input)
|
|
|
|
err := validateReceivingSidesDoNotOverlap(tc.input)
|
|
|
|
if tc.err {
|
|
|
|
assert.Error(t, err)
|
|
|
|
} else {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
|
|
|
|
func TestJobIDErrorHandling(t *testing.T) {
|
|
|
|
tmpl := `
|
|
|
|
jobs:
|
|
|
|
- name: %s
|
|
|
|
type: push
|
|
|
|
connect:
|
|
|
|
type: local
|
|
|
|
listener_name: foo
|
|
|
|
client_identity: bar
|
|
|
|
filesystems: {"<": true}
|
|
|
|
snapshotting:
|
|
|
|
type: manual
|
|
|
|
pruning:
|
|
|
|
keep_sender:
|
|
|
|
- type: last_n
|
|
|
|
count: 10
|
|
|
|
keep_receiver:
|
|
|
|
- type: last_n
|
|
|
|
count: 10
|
|
|
|
`
|
|
|
|
fill := func(s string) string { return fmt.Sprintf(tmpl, s) }
|
|
|
|
|
|
|
|
type Case struct {
|
|
|
|
jobName string
|
|
|
|
valid bool
|
|
|
|
}
|
|
|
|
cases := []Case{
|
|
|
|
{"validjobname", true},
|
|
|
|
{"valid with spaces", true},
|
|
|
|
{"invalid\twith\ttabs", false},
|
|
|
|
{"invalid#withdelimiter", false},
|
|
|
|
{"invalid@withdelimiter", false},
|
|
|
|
{"withnewline\\nmiddle", false},
|
|
|
|
{"withnewline\\n", false},
|
|
|
|
{"withslash/", false},
|
|
|
|
{"withslash/inthemiddle", false},
|
|
|
|
{"/", false},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range cases {
|
|
|
|
t.Run(cases[i].jobName, func(t *testing.T) {
|
|
|
|
c := cases[i]
|
|
|
|
|
|
|
|
conf, err := config.ParseConfigBytes([]byte(fill(c.jobName)))
|
|
|
|
require.NoError(t, err, "not expecting yaml-config to know about job ids")
|
|
|
|
require.NotNil(t, conf)
|
2022-03-30 04:39:10 +02:00
|
|
|
jobs, err := JobsFromConfig(conf, config.ParseFlagsNone)
|
new features: {resumable,encrypted,hold-protected} send-recv, last-received-hold
- **Resumable Send & Recv Support**
No knobs required, automatically used where supported.
- **Hold-Protected Send & Recv**
Automatic ZFS holds to ensure that we can always resume a replication step.
- **Encrypted Send & Recv Support** for OpenZFS native encryption.
Configurable at the job level, i.e., for all filesystems a job is responsible for.
- **Receive-side hold on last received dataset**
The counterpart to the replication cursor bookmark on the send-side.
Ensures that incremental replication will always be possible between a sender and receiver.
Design Doc
----------
`replication/design.md` doc describes how we use ZFS holds and bookmarks to ensure that a single replication step is always resumable.
The replication algorithm described in the design doc introduces the notion of job IDs (please read the details on this design doc).
We reuse the job names for job IDs and use `JobID` type to ensure that a job name can be embedded into hold tags, bookmark names, etc.
This might BREAK CONFIG on upgrade.
Protocol Version Bump
---------------------
This commit makes backwards-incompatible changes to the replication/pdu protobufs.
Thus, bump the version number used in the protocol handshake.
Replication Cursor Format Change
--------------------------------
The new replication cursor bookmark format is: `#zrepl_CURSOR_G_${this.GUID}_J_${jobid}`
Including the GUID enables transaction-safe moving-forward of the cursor.
Including the job id enables that multiple sending jobs can send the same filesystem without interfering.
The `zrepl migrate replication-cursor:v1-v2` subcommand can be used to safely destroy old-format cursors once zrepl has created new-format cursors.
Changes in This Commit
----------------------
- package zfs
- infrastructure for holds
- infrastructure for resume token decoding
- implement a variant of OpenZFS's `entity_namecheck` and use it for validation in new code
- ZFSSendArgs to specify a ZFS send operation
- validation code protects against malicious resume tokens by checking that the token encodes the same send parameters that the send-side would use if no resume token were available (i.e. same filesystem, `fromguid`, `toguid`)
- RecvOptions support for `recv -s` flag
- convert a bunch of ZFS operations to be idempotent
- achieved through more differentiated error message scraping / additional pre-/post-checks
- package replication/pdu
- add field for encryption to send request messages
- add fields for resume handling to send & recv request messages
- receive requests now contain `FilesystemVersion To` in addition to the filesystem into which the stream should be `recv`d into
- can use `zfs recv $root_fs/$client_id/path/to/dataset@${To.Name}`, which enables additional validation after recv (i.e. whether `To.Guid` matched what we received in the stream)
- used to set `last-received-hold`
- package replication/logic
- introduce `PlannerPolicy` struct, currently only used to configure whether encrypted sends should be requested from the sender
- integrate encryption and resume token support into `Step` struct
- package endpoint
- move the concepts that endpoint builds on top of ZFS to a single file `endpoint/endpoint_zfs.go`
- step-holds + step-bookmarks
- last-received-hold
- new replication cursor + old replication cursor compat code
- adjust `endpoint/endpoint.go` handlers for
- encryption
- resumability
- new replication cursor
- last-received-hold
- client subcommand `zrepl holds list`: list all holds and hold-like bookmarks that zrepl thinks belong to it
- client subcommand `zrepl migrate replication-cursor:v1-v2`
2019-09-11 17:19:17 +02:00
|
|
|
|
|
|
|
if c.valid {
|
|
|
|
assert.NoError(t, err)
|
|
|
|
require.Len(t, jobs, 1)
|
|
|
|
assert.Equal(t, c.jobName, jobs[0].Name())
|
|
|
|
} else {
|
|
|
|
t.Logf("error: %s", err)
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Nil(t, jobs)
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-07-19 23:59:33 +02:00
|
|
|
|
|
|
|
func TestSampleConfigsAreBuiltWithoutErrors(t *testing.T) {
|
|
|
|
paths, err := filepath.Glob("../../config/samples/*")
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("glob failed: %+v", err)
|
|
|
|
}
|
|
|
|
|
2021-07-09 16:30:44 +02:00
|
|
|
type additionalCheck struct {
|
|
|
|
state int
|
|
|
|
test func(t *testing.T, jobs []Job)
|
|
|
|
}
|
|
|
|
additionalChecks := map[string]*additionalCheck{
|
|
|
|
"bandwidth_limit.yml": {test: testSampleConfig_BandwidthLimit},
|
|
|
|
}
|
|
|
|
|
2020-07-19 23:59:33 +02:00
|
|
|
for _, p := range paths {
|
|
|
|
|
|
|
|
if path.Ext(p) != ".yml" {
|
|
|
|
t.Logf("skipping file %s", p)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2021-07-09 16:30:44 +02:00
|
|
|
filename := path.Base(p)
|
|
|
|
t.Logf("checking for presence additonal checks for file %q", filename)
|
|
|
|
additionalCheck := additionalChecks[filename]
|
|
|
|
if additionalCheck == nil {
|
|
|
|
t.Logf("no additional checks")
|
|
|
|
} else {
|
|
|
|
t.Logf("additional check present")
|
|
|
|
additionalCheck.state = 1
|
|
|
|
}
|
|
|
|
|
2020-07-19 23:59:33 +02:00
|
|
|
t.Run(p, func(t *testing.T) {
|
|
|
|
c, err := config.ParseConfig(p)
|
|
|
|
if err != nil {
|
2021-07-09 16:30:44 +02:00
|
|
|
t.Fatalf("error parsing %s:\n%+v", p, err)
|
2020-07-19 23:59:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("file: %s", p)
|
|
|
|
t.Log(pretty.Sprint(c))
|
|
|
|
|
2022-03-30 04:39:10 +02:00
|
|
|
jobs, err := JobsFromConfig(c, config.ParseFlagsNoCertCheck)
|
2020-07-19 23:59:33 +02:00
|
|
|
t.Logf("jobs: %#v", jobs)
|
2021-07-09 16:30:44 +02:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
if additionalCheck != nil {
|
|
|
|
additionalCheck.test(t, jobs)
|
|
|
|
additionalCheck.state = 2
|
|
|
|
}
|
2020-07-19 23:59:33 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-07-09 16:30:44 +02:00
|
|
|
for basename, c := range additionalChecks {
|
|
|
|
if c.state == 0 {
|
|
|
|
panic("univisited additional check " + basename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func testSampleConfig_BandwidthLimit(t *testing.T, jobs []Job) {
|
|
|
|
require.Len(t, jobs, 3)
|
|
|
|
|
|
|
|
{
|
|
|
|
limitedSink, ok := jobs[0].(*PassiveSide)
|
|
|
|
require.True(t, ok, "%T", jobs[0])
|
|
|
|
limitedSinkMode, ok := limitedSink.mode.(*modeSink)
|
|
|
|
require.True(t, ok, "%T", limitedSink)
|
|
|
|
|
|
|
|
assert.Equal(t, int64(12345), limitedSinkMode.receiverConfig.BandwidthLimit.Max)
|
|
|
|
assert.Equal(t, int64(1<<17), limitedSinkMode.receiverConfig.BandwidthLimit.BucketCapacity)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
limitedPush, ok := jobs[1].(*ActiveSide)
|
|
|
|
require.True(t, ok, "%T", jobs[1])
|
|
|
|
limitedPushMode, ok := limitedPush.mode.(*modePush)
|
|
|
|
require.True(t, ok, "%T", limitedPush)
|
|
|
|
|
|
|
|
assert.Equal(t, int64(54321), limitedPushMode.senderConfig.BandwidthLimit.Max)
|
|
|
|
assert.Equal(t, int64(1024), limitedPushMode.senderConfig.BandwidthLimit.BucketCapacity)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
unlimitedSink, ok := jobs[2].(*PassiveSide)
|
|
|
|
require.True(t, ok, "%T", jobs[2])
|
|
|
|
unlimitedSinkMode, ok := unlimitedSink.mode.(*modeSink)
|
|
|
|
require.True(t, ok, "%T", unlimitedSink)
|
|
|
|
|
|
|
|
max := unlimitedSinkMode.receiverConfig.BandwidthLimit.Max
|
|
|
|
assert.Less(t, max, int64(0), max, "unlimited mode <=> negative value for .Max, see bandwidthlimit.Config")
|
|
|
|
}
|
|
|
|
|
2020-07-19 23:59:33 +02:00
|
|
|
}
|
2021-02-28 23:33:28 +01:00
|
|
|
|
|
|
|
func TestReplicationOptions(t *testing.T) {
|
|
|
|
tmpl := `
|
|
|
|
jobs:
|
|
|
|
- name: foo
|
|
|
|
type: push
|
|
|
|
connect:
|
|
|
|
type: local
|
|
|
|
listener_name: foo
|
|
|
|
client_identity: bar
|
|
|
|
filesystems: {"<": true}
|
|
|
|
%s
|
|
|
|
snapshotting:
|
|
|
|
type: manual
|
|
|
|
pruning:
|
|
|
|
keep_sender:
|
|
|
|
- type: last_n
|
|
|
|
count: 10
|
|
|
|
keep_receiver:
|
|
|
|
- type: last_n
|
|
|
|
count: 10
|
|
|
|
`
|
|
|
|
|
|
|
|
type Test struct {
|
|
|
|
name string
|
|
|
|
input string
|
|
|
|
expectOk func(t *testing.T, a *ActiveSide, m *modePush)
|
|
|
|
expectError bool
|
|
|
|
}
|
|
|
|
|
|
|
|
tests := []Test{
|
|
|
|
{
|
|
|
|
name: "defaults",
|
|
|
|
input: `
|
|
|
|
replication: {}
|
|
|
|
`,
|
|
|
|
expectOk: func(t *testing.T, a *ActiveSide, m *modePush) {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "steps_zero",
|
|
|
|
input: `
|
|
|
|
replication:
|
|
|
|
concurrency:
|
|
|
|
steps: 0
|
|
|
|
`,
|
|
|
|
expectError: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "size_estimates_zero",
|
|
|
|
input: `
|
|
|
|
replication:
|
|
|
|
concurrency:
|
|
|
|
size_estimates: 0
|
|
|
|
`,
|
|
|
|
expectError: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "custom_values",
|
|
|
|
input: `
|
|
|
|
replication:
|
|
|
|
concurrency:
|
|
|
|
steps: 23
|
|
|
|
size_estimates: 42
|
|
|
|
`,
|
|
|
|
expectOk: func(t *testing.T, a *ActiveSide, m *modePush) {
|
|
|
|
assert.Equal(t, 23, a.replicationDriverConfig.StepQueueConcurrency)
|
|
|
|
assert.Equal(t, 42, m.plannerPolicy.SizeEstimationConcurrency)
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "negative_values_forbidden",
|
|
|
|
input: `
|
|
|
|
replication:
|
|
|
|
concurrency:
|
|
|
|
steps: -23
|
|
|
|
size_estimates: -42
|
|
|
|
`,
|
|
|
|
expectError: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
fill := func(s string) string { return fmt.Sprintf(tmpl, s) }
|
|
|
|
|
|
|
|
for _, ts := range tests {
|
|
|
|
t.Run(ts.name, func(t *testing.T) {
|
|
|
|
assert.True(t, (ts.expectError) != (ts.expectOk != nil))
|
|
|
|
|
|
|
|
cstr := fill(ts.input)
|
|
|
|
t.Logf("testing config:\n%s", cstr)
|
|
|
|
c, err := config.ParseConfigBytes([]byte(cstr))
|
|
|
|
require.NoError(t, err)
|
2022-03-30 04:39:10 +02:00
|
|
|
jobs, err := JobsFromConfig(c, config.ParseFlagsNone)
|
2021-02-28 23:33:28 +01:00
|
|
|
if ts.expectOk != nil {
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, c)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, jobs, 1)
|
|
|
|
a := jobs[0].(*ActiveSide)
|
|
|
|
m := a.mode.(*modePush)
|
|
|
|
ts.expectOk(t, a, m)
|
|
|
|
} else if ts.expectError {
|
|
|
|
require.Error(t, err)
|
|
|
|
} else {
|
|
|
|
t.Fatalf("test must define expectOk or expectError")
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|