-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rohit-PX <rkulkarni@purestorage.com>
- Loading branch information
Rohit-PX
committed
Mar 9, 2023
1 parent
6e7426d
commit a236b6e
Showing
5 changed files
with
185 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package integrationtest | ||
|
||
import ( | ||
"html/template" | ||
"os" | ||
"testing" | ||
|
||
"github.com/libopenstorage/stork/pkg/apis/stork/v1alpha1" | ||
"github.com/libopenstorage/stork/pkg/utils" | ||
storkops "github.com/portworx/sched-ops/k8s/stork" | ||
"github.com/portworx/torpedo/drivers/scheduler" | ||
"github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMigrationExportStats(t *testing.T) { | ||
t.Run("migrationStatsExportTest", migrationStatsExportTest) | ||
t.Run("migrationStatsDisplayTest", migrationStatsDisplayTest) | ||
} | ||
|
||
func migrationStatsExportTest(t *testing.T) { | ||
var err error | ||
// Reset config in case of error | ||
defer func() { | ||
err = setSourceKubeConfig() | ||
require.NoError(t, err, "Error resetting source config") | ||
}() | ||
|
||
migrationKey := "mysql-migration" | ||
migrationAppKey := "mysql-1-pvc" | ||
includeResourcesFlag := true | ||
startApplicationsFlag := false | ||
|
||
currCtxs, err := schedulerDriver.Schedule(migrationKey, | ||
scheduler.ScheduleOptions{AppKeys: []string{migrationAppKey}}) | ||
require.NoError(t, err, "Error scheduling task") | ||
require.Equal(t, 1, len(currCtxs), "Only one task should have started") | ||
|
||
err = schedulerDriver.WaitForRunning(currCtxs[0], defaultWaitTimeout, defaultWaitInterval) | ||
require.NoError(t, err, "Error waiting for app to get to running state") | ||
|
||
// create, apply and validate cluster pair specs | ||
err = scheduleClusterPair(currCtxs[0], false, true, defaultClusterPairDir, "", false) | ||
require.NoError(t, err, "Error scheduling cluster pair") | ||
|
||
currMigNamespace := migrationAppKey + "-" + migrationKey | ||
currMig, err := createMigration(t, migrationKey, currMigNamespace, "remoteclusterpair", currMigNamespace, &includeResourcesFlag, &startApplicationsFlag) | ||
require.NoError(t, err, "failed to create migration: %s in namespace %s", migrationKey, currMigNamespace) | ||
|
||
migrationList := []*v1alpha1.Migration{currMig} | ||
err = WaitForMigration(migrationList) | ||
require.NoError(t, err, "error in migrations for exported stats") | ||
|
||
finishedMig, err := storkops.Instance().GetMigration(currMig.Name, currMig.Namespace) | ||
require.Nil(t, err, "could not get completed migration") | ||
|
||
logrus.Infof("Migration Object Status: %v", finishedMig.Status.Summary) | ||
exportableStat := utils.GetExportableStatsFromMigrationObject(finishedMig) | ||
require.NotNil(t, exportableStat, "could not fetch stats from migration object") | ||
|
||
// Export stats to Aetos Mongo DB | ||
err = utils.WriteMigrationStatsToAetos(exportableStat) | ||
require.NoError(t, err, "error while writing stats to mongo DB") | ||
|
||
// Get stats from Aetos Mongo DB | ||
stats, err := utils.GetMigrationStatsFromAetos(utils.AetosStatsURL) | ||
require.NoError(t, err, "error while fetching stats from mongo DB") | ||
|
||
// Print stats to the console for now | ||
utils.PrettyStruct(stats) | ||
} | ||
|
||
func migrationStatsDisplayTest(t *testing.T) { | ||
var err error | ||
// Get stats from Aetos Mongo DB | ||
stats, err := utils.GetMigrationStatsFromAetos(utils.AetosStatsURL) | ||
require.NoError(t, err, "error while fetching stats from mongo DB") | ||
|
||
// Print stats to the console for now | ||
utils.PrettyStruct(stats) | ||
|
||
paths := []string{ | ||
"/specs/stats.tmpl", | ||
} | ||
|
||
// create a new file | ||
//err := os.MkdirAll("/reports", 0777) | ||
file, _ := os.Create("/reports/migstats.html") | ||
|
||
templ := template.Must(template.ParseFiles(paths...)) | ||
err = templ.Execute(file, stats) | ||
if err != nil { | ||
panic(err) | ||
} | ||
file.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Go To-Do list</title> | ||
</head> | ||
<body> | ||
<p> | ||
Stats for migration: | ||
</p> | ||
<table border="2"> | ||
<tr> | ||
<td>Name</td> | ||
<td>Version</td> | ||
<td>Total Volumes</td> | ||
<td>Migrated Volume</td> | ||
<td>Total Resources</td> | ||
<td>Migrated Resources</td> | ||
<td>Total Bytes Migrated</td> | ||
<td>Elapsed time for Volume Migration</td> | ||
<td>Elapsed time for Resource Migration</td> | ||
</tr> | ||
{{ range $idx, $item := . }} | ||
<tr> | ||
<td>{{ $item.Name }}</td> | ||
<td>{{ $item.StorkVersion }}</td> | ||
<td>{{ $item.PortworxVersion }}</td> | ||
<td>{{ $item.Data.TotalNumberOfVolumes }}</td> | ||
<td>{{ $item.Data.NumOfMigratedVolumes }}</td> | ||
<td>{{ $item.Data.TotalNumberOfResources }}</td> | ||
<td>{{ $item.Data.NumOfMigratedResources }}</td> | ||
<td>{{ $item.Data.TotalBytesMigrated }}</td> | ||
<td>{{ $item.Data.ElapsedTimeForVolumeMigration }}</td> | ||
<td>{{ $item.Data.ElapsedTimeForResourceMigration }}</td> | ||
</tr> | ||
{{ end }} | ||
</table> | ||
</body> | ||
</html> |