forked from lf-edge/edge-home-orchestration-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initialization of the file system for the orchestrator (lf-edge#318)
Signed-off-by: Taras Drozdovskyi <t.drozdovsky@samsung.com> - If the file system required to work of edge-orchestration is not yet created, then it creates file system. - This commit is for resolving the above painpoint by adding the initiation of the file system for the orchestrator.
- Loading branch information
1 parent
9c3b146
commit 3722c32
Showing
8 changed files
with
144 additions
and
41 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
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,65 @@ | ||
/******************************************************************************* | ||
* Copyright 2021 Samsung Electronics All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*******************************************************************************/ | ||
|
||
package fscreator | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/lf-edge/edge-home-orchestration-go/internal/common/logmgr" | ||
) | ||
|
||
const ( | ||
logPrefix = "[fscreator]" | ||
) | ||
|
||
var edgeDirs = []string{ | ||
"/apps", | ||
"/data/db", | ||
"/data/cert", | ||
"/datastorage", | ||
"/device", | ||
"/log", | ||
"/mnedc", | ||
"/user", | ||
} | ||
|
||
var ( | ||
log = logmgr.GetInstance() | ||
) | ||
|
||
// CreateFileSystem creates a file system necessary for the work of the edge-orchestration | ||
// ├── var | ||
// └── edge-orchestration | ||
// ├── apps | ||
// ├── data | ||
// │ ├── cert | ||
// │ └── db | ||
// ├── datastorage | ||
// ├── device | ||
// ├── log | ||
// ├── mnedc | ||
// └── user | ||
func CreateFileSystem(edgeDir string) error { | ||
for _, dir := range edgeDirs { | ||
if err := os.MkdirAll(edgeDir+dir, os.ModePerm); err != nil { | ||
log.Panicf("%s Failed to create %s: %s\n", logPrefix, edgeDir+dir, err) | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
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,57 @@ | ||
/******************************************************************************* | ||
* Copyright 2021 Samsung Electronics All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*******************************************************************************/ | ||
|
||
package fscreator | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
const ( | ||
fakefsPath = "fakefs" | ||
unexpectedSuccess = "unexpected success" | ||
unexpectedFail = "unexpected fail" | ||
) | ||
|
||
func TestCreateFileSystem(t *testing.T) { | ||
t.Run("Success", func(t *testing.T) { | ||
defer os.RemoveAll(fakefsPath) | ||
|
||
CreateFileSystem(fakefsPath) | ||
for _, dir := range edgeDirs { | ||
if _, err := os.Stat(fakefsPath+dir); err != nil { | ||
t.Error(err.Error()) | ||
} | ||
} | ||
}) | ||
|
||
t.Run("Error", func(t *testing.T) { | ||
defer func() { | ||
if r := recover(); r == nil { | ||
t.Error(r) | ||
} | ||
for _, dir := range edgeDirs { | ||
if _, err := os.Stat("/"+fakefsPath+dir); err == nil { | ||
t.Error(unexpectedSuccess) | ||
} | ||
} | ||
os.RemoveAll("/"+fakefsPath) | ||
}() | ||
CreateFileSystem("/"+fakefsPath) | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.